Skip to content

fix: keep what Alpine hides hidden until Alpine starts - #10

Merged
ogorzalka merged 1 commit into
mainfrom
fix/alpine-cloak
Sep 25, 2026
Merged

ogorzalka merged 1 commit into
mainfrom
fix/alpine-cloak

Conversation

@ogorzalka

Copy link
Copy Markdown
Member

Problem (reported by the maintainer)

On page load, elements that Alpine hides with x-show show up briefly: cart drawer, mobile menu, add-to-cart modal, product accordion…

  • No CSS rule hid [x-cloak], so the 7 x-cloak attributes already present did nothing.
  • About twenty x-show elements had no x-cloak at all.

Measured with the theme's JS blocked (the moment before Alpine starts), on pollora-test:

page x-show elements visible before Alpine
home 10 (6 open panels, the add-to-cart modal content…)
product 11 (+ the description accordion panel)

Fix

  • app.css: [x-cloak] { display: none !important; }. An attribute selector: no Tailwind utility replaces it.
  • x-cloak on every x-show element, 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.
  • Dead class: first-hidden-state removed (no rule ever styled it).

Test (bin/tests/e2e/alpine.spec.ts)

With the theme's JS blocked, no x-show element may be visible on the home page or on a product page (a product is created via REST, then deleted).

Measured locally:

  • Without the fix: 10 and 11 elements visible, the test fails.
  • With the views fixed and the [x-cloak] rule injected (simulating the rebuilt CSS): 0 and 0.
  • With Alpine running: no x-cloak left, and the accordion still opens.

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.
@ogorzalka
ogorzalka merged commit 7cac0b2 into main Sep 25, 2026
6 checks passed
@ogorzalka
ogorzalka deleted the fix/alpine-cloak branch September 25, 2026 15:30
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.

1 participant