fix: keep what Alpine hides hidden until Alpine starts - #10
Merged
Merged
Conversation
Elements hidden with x-show were shown until Alpine initialised them, so the cart drawer, the mobile menu, the add-to-cart modal and the product accordion flashed on every page load. Seven elements already carried x-cloak, but no stylesheet rule hid [x-cloak], so it did nothing; the others had none. Measured with the theme's scripts held back: 10 elements Alpine hides were on screen on the home page, 11 on a product page. The stylesheet hides [x-cloak], and every x-show element carries it — but the billing address card, which is shown from the start when the address is prefilled, as the fields next to it already did. The dead first-hidden-state class, which no rule ever styled, goes. A browser spec holds the theme's scripts back and expects nothing Alpine hides on screen, on the home page and on a product page. Measured on a site with the rule injected: none before Alpine starts; once it has, no x-cloak is left and the accordion still opens.
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.
Problem (reported by the maintainer)
On page load, elements that Alpine hides with
x-showshow up briefly: cart drawer, mobile menu, add-to-cart modal, product accordion…[x-cloak], so the 7x-cloakattributes already present did nothing.x-showelements had nox-cloakat all.Measured with the theme's JS blocked (the moment before Alpine starts), on pollora-test:
x-showelements visible before Alpineopenpanels, the add-to-cart modal content…)Fix
app.css:[x-cloak] { display: none !important; }. An attribute selector: no Tailwind utility replaces it.x-cloakon everyx-showelement, with one exception: the billing address card, shown from the start when the address is prefilled. It gets@unless ($prefilled) x-cloak @endunless, the same logic its neighbouring block already used.first-hidden-stateremoved (no rule ever styled it).Test (
bin/tests/e2e/alpine.spec.ts)With the theme's JS blocked, no
x-showelement may be visible on the home page or on a product page (a product is created via REST, then deleted).Measured locally:
[x-cloak]rule injected (simulating the rebuilt CSS): 0 and 0.x-cloakleft, and the accordion still opens.