-
-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: hydration mismatches by saving changed tokens #467
base: main
Are you sure you want to change the base?
Conversation
Open in CodeSandbox Web Editor | VS Code | VS Code Insiders |
Run & review this pull request in StackBlitz Codeflow. |
|
Hi folks!
When using twind v1 on Deno's Fresh I faced this TBT performance issue. Taking a deeper look into the performance bottleneck, I noticed we had two main performance issues.
The first one was clearing the style sheet, which causes the browser to "recalculate the style", creating a long task. To fix this issue, I just stopped clearing the sheet on resume.
The second issue is a little more subtle. Turns out that this translate function takes a long time to execute. It's usually ok when dynamically changing styles, however, when running it alongside (P)react's hydration, it can greatly increase this task's blocking time. The puzzling piece is that this part of the code should never be reached if the sheet's resume process occurs successfully. Investigating further, I noticed that tokens like
md:(w-full h-full)
get translated into the final html asmd:w-full md:h-full
, so when the tw's cache is resumed, the initial tokens are missing. To address this issue I made this cache to be resumable too by adding a new extractedjson
parameter that can be added as aThe nice thing about it is that it only stores the tokens where
tw(token) != token
, not adding any unnecessary bloat to the final html.After applying these two performance improvements, my app's blocking time went from: 700ish ms to 150ish ms on Google's Page Speed Insights.
Another solution to this problem would be to make this
translate
function much faster, however I could not really understand how to do this.Let me know if you have a better idea than shipping the tw's cache to the final html.
Thanks!
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and verify the project withpnpm check
Changesets
pnpx changeset
and following the prompts. All changesets should bepatch
until Twind 1.0