Skip to content
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

Remove unnecessary Tailwind class compilation calls #6534

Merged
merged 9 commits into from
Oct 21, 2024

Conversation

bkrmendy
Copy link
Contributor

@bkrmendy bkrmendy commented Oct 15, 2024

Editions store

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

Copy link
Contributor

github-actions bot commented Oct 15, 2024

Try me

Copy link

relativeci bot commented Oct 15, 2024

#14863 Bundle Size — 57.98MiB (~+0.01%).

243afaf(current) vs 916e8b9 master#14861(baseline)

Warning

Bundle contains 70 duplicate packages – View duplicate packages

Bundle metrics  Change 2 changes Regression 1 regression
                 Current
#14863
     Baseline
#14861
Regression  Initial JS 40.97MiB(~+0.01%) 40.97MiB
No change  Initial CSS 0B 0B
Change  Cache Invalidation 18% 17.88%
No change  Chunks 20 20
No change  Assets 22 22
No change  Modules 4153 4153
No change  Duplicate Modules 213 213
No change  Duplicate Code 27.33% 27.33%
No change  Packages 477 477
No change  Duplicate Packages 70 70
Bundle size by type  Change 2 changes Regression 1 regression Improvement 1 improvement
                 Current
#14863
     Baseline
#14861
Regression  JS 57.98MiB (~+0.01%) 57.97MiB
Improvement  HTML 7.37KiB (-0.25%) 7.39KiB

Bundle analysis reportBranch fix/tailwind-fine-grained-dom-ob...Project dashboard


Generated by RelativeCIDocumentationReport issue

@bkrmendy bkrmendy marked this pull request as ready for review October 17, 2024 10:12
@bkrmendy bkrmendy marked this pull request as draft October 17, 2024 15:36
@bkrmendy bkrmendy changed the title Fine-grained Tailwind DOM observer Remove unnecessary Tailwind class compilation Oct 18, 2024
@bkrmendy bkrmendy marked this pull request as ready for review October 18, 2024 10:21
@bkrmendy bkrmendy changed the title Remove unnecessary Tailwind class compilation Remove unnecessary Tailwind class compilation class Oct 21, 2024
@bkrmendy bkrmendy changed the title Remove unnecessary Tailwind class compilation class Remove unnecessary Tailwind class compilation calls Oct 21, 2024
@bkrmendy bkrmendy merged commit fd3e0ad into master Oct 21, 2024
15 checks passed
@bkrmendy bkrmendy deleted the fix/tailwind-fine-grained-dom-observer branch October 21, 2024 12:07
liady pushed a commit that referenced this pull request Dec 13, 2024
# [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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants