twind
twind copied to clipboard
fix: Partial solution for stale sheet reference in setup call
Partial fix for #321
By delaying getSheet() until AFTER destroy() has been called, we can ensure a fresh reference to sheet. Else getSheet() might create a reference to a <style> tag in the head of the doc, which gets removed by destroy, but then loaded up with the new styles from observe.
This will only fix setup, install is still very susceptible to this issue:
https://github.com/tw-in-js/twind/blob/f9e9f842dffefa6622ac7a7493f728431841e642/packages/twind/src/install.ts#L20-L27
I'm not sure how to go about fixing that as it's more of an API-level issue I think. So long as destroy() can do something like remove a <style> tag, sheet could be an outdated reference to something that no longer (functionally) exists.
Pull Request Test Coverage Report for Build 2297794071
Details
- 3 of 3 (100.0%) changed or added relevant lines in 1 file are covered.
- No unchanged relevant lines lost coverage.
- Overall coverage increased (+0.001%) to 98.464%
| Totals | |
|---|---|
| Change from base Build 2295915872: | 0.001% |
| Covered Lines: | 7341 |
| Relevant Lines: | 7433 |
💛 - Coveralls
Was thinking, alternatively, maybe the call to destroy() should just be replaced with clear()? Not sure on the implications there, will need to test it out tomorrow.
Thank you. Based on your idea I updated to code to create the sheet after the previous one had been destroyed (0e2aa5c)