-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove unnecessary Tailwind class compilation calls (#6534)
# [Editions store](https://utopia.fish/p/2e4310b0-nostalgic-blackberry/?branch_name=fix-tailwind-fine-grained-dom-observer) ## Problem The Tailwind class generation code was running twice at the end of an interaction. Instead, we only want to re-run the tailwind compilation code when - a new element is added to the DOM or the `class` attribute of an element is updated - the Tailwind config file is updated (so tweaks to the tailwind config show up right away on the canvas) ## Fix - remove the `RequireFn` param from `useTailwindCompilation`. This param is problematic because a new `requireFn` is passed to `useTailwindCompilation` whenever `projectContents` changes, which triggers a re-compilation. Instead, the require fn is constructed in a `useRefEditorState` and used through that ref - The Tailwind config file is selected with a hook using `createSelector` for memoization - The mutation observer that runs the Tailwind class generation is only run if there were new nodes added (with potentially new Tailwind classes added to the DOM) or a `class` attribute was updated (with a potentially new Tailwind class) ### Out of scope This PR doesn't deal with the problem of generating new Tailwind classes only for the elements that have changed. This is due to how the library we use for tailwind class compilation works, finding a more fine-grained way to do this would be a more involved task ### Details - The PR also adds a test that tests tailwind style generation with Remix navigation
- Loading branch information
Showing
3 changed files
with
230 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters