Repository navigation
🍕 vite: mount components added after page load - #294
Conversation
A clay:mount event from an element mounts the components at or under it (detail.mounted is a promise for when they are done), and autoMount: true in claycli.config.js mounts added component elements with a MutationObserver. Both share one mount path: each element mounts once, a run waits for elements another run is still mounting, and a failed module load can be retried. The page-load mount is unchanged.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
This works well for me locally. Claude had one nit, but it doesn't apply to us as we've managed to ditch DS
Mounts elements removed while their module loads (line 206). The "is it still on the page" check (isConnected) only runs when an element is claimed. An infinite-scroll item or modal removed before its module loads still mounts on the detached node and leaks listeners and timers. The fix is cheap: check again just before mod(el) / DS.get.
A run claimed an element while it was on the page, then mounted it once its module (or a legacy controller's dependencies) loaded, even if it had been removed by then. Check again right before mounting: skip it, and release it so it mounts if it comes back. Page load gets the same check.
|
Thanks for trying it. That nit applies without DS too: a Fixed in 6f6eb2b: the runtime checks again right before |
|
@codex review this once more. |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
What does this PR do?
Lets the Vite bootstrap mount components whose HTML is added after page load, in two ways:
clay:mountevent (always on): dispatch it from an element that holds new HTML, and the bootstrap mounts the components at or under it. Pass an object asdetailto get a promise ondetail.mounted.autoMount(opt-in,autoMount: trueinclaycli.config.js): aMutationObservermounts component elements as they are added, with no event.Both go through one mount path. Each element mounts once, and a run that finds one still mounting waits for it. An element whose module failed to load, or whose legacy controller had no
DSyet, can be tried again. An element that is off the page by the time its module (or a legacy controller's dependencies) is ready is skipped, and mounts if it comes back.Page load keeps the same preload barrier and
clay-componentsmeasure. One change there: a component removed by another component's mount before its turn is now skipped; before, it was mounted off the page.No issue: pages need this for infinite scroll, lazy recirculation, server-fetched modals and articles restored after load.
Why are we doing this? Any context or related work?
Under
clay vitethe bootstrap mounts only what is on the page when it runs. Pages that add server-rendered component HTML later had no supported way to run those components'client.js.Where should a reviewer start?
mountElsin the runtime inlib/cmd/vite/generate-bootstrap.js, used by page load, the event andautoMount. Then the CLAY-VITE.md section "Components added after page load".Manual testing steps?
npm test: 32 suites, 737 tests, lint clean. Each new rule has a test that fails when its code is removed.MutationObserver), 20 scenarios:data-urichanged while its module loadsdocument,windowor a detached nodeautoMounton inserted HTML, HTML inserted and removed in one task, and moved elementsautoMountoff and on. Both parse, and they differ only by the_clayAutoMountline. The edit-mode bootstrap has no mount runtime.Screenshots
None.
Additional Context
autoMountis off by default. Code that copies a component element (cloneNode) or inserts component HTML and then mounts it itself would mount it twice. In sites,sticky-container(its newsletter copy) andsubscription-form-gift-recipientdo this; drop those mount calls before turning it on.