Move custom element display rules from JS to CSS to prevent CLS#2400
Open
joshhanley wants to merge 1 commit intomainfrom
Open
Move custom element display rules from JS to CSS to prevent CLS#2400joshhanley wants to merge 1 commit intomainfrom
joshhanley wants to merge 1 commit intomainfrom
Conversation
Add display rules for all custom elements (`ui-select`, `ui-description`, `ui-checkbox`, `ui-switch`, `ui-radio`, etc.) to `flux.css` inside `@layer base`. Previously these were only set at runtime via JS `inject()` calls, causing layout shift between CSS loading and JS execution.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Scenario
When using Flux custom elements like
<flux:description>,<flux:label>,<flux:checkbox>, or<flux:switch>, there is a visible layout shift (CLS) on first paint. Elements briefly render asdisplay: inline(the browser default for unknown elements), then snap to their correct display value once JavaScript executes.This is most noticeable on elements visible at first paint — particularly
ui-descriptionwith longer text that wraps differently atinlinevsblock:The Problem
Display values for ~30 custom elements are set exclusively at runtime via JavaScript
inject()calls — one per component file (e.g.js/field.js,js/select.js,js/checkbox.js). Theinject()function usesdocument.adoptedStyleSheetsto create CSS rules dynamically:Until JS executes, browsers render these unknown elements as
display: inline, causing the layout shift. Onlyui-buttonhad a pre-existing CSS rule influx.css.The Solution
Move all custom element display rules into
flux.cssinside an@layer baseblock, so they apply from first paint while still allowing Tailwind utility classes to override them.This PR adds the CSS rules. The corresponding
inject()calls are removed from the JS source files in a companion PR (livewire/flux-pro#446).Fixes #2394