Repository navigation
Conversation
1af0e73 to
1e278c7
Compare
|
@codex review this |
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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1e278c753e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
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".
| // Claimed before any module loads, so an overlapping run cannot take it too | ||
| if (claimedEls.get(el) === uri) return false; | ||
| claimedEls.set(el, uri); |
There was a problem hiding this comment.
Await in-flight mounts when handling overlapping events
When two clay:mount events cover an element whose module is still loading, the second run filters out the claimed element and resolves its detail.mounted promise before the controller runs. This violates the documented guarantee that the promise resolves once every element has mounted or failed, allowing callers to proceed against uninitialized components. Retain and await the existing per-element mount promise while still preventing a duplicate controller invocation.
Useful? React with 👍 / 👎.
| var uri = el.dataset.uri; | ||
| var m = CLAY_INSTANCE_KIND.exec(uri); |
There was a problem hiding this comment.
Invalidate pending mounts when an element's URI changes
In the newly supported element-reuse flow, changing data-uri and dispatching another event while the previous import is pending leaves both runs targeting the same element with different captured URIs. The new controller can mount first, after which the old controller still runs against the repurposed DOM—for example, a slow recirc controller initializes an element already mounted as video. Verify that the element still owns the same claim/generation immediately before invoking either controller path, including after the DS dependency wait.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Is a changing data-uri really likely?
There was a problem hiding this comment.
I have decided it really isn't - so I'll remove support for it and that should also remove this issue.
| function isOnPage(name) { | ||
| if (!onPage) { | ||
| onPage = {}; | ||
| document.querySelectorAll(COMPONENT_SELECTOR).forEach(function(el) { |
There was a problem hiding this comment.
Include scoped shadow-tree components in dependency discovery
When the documented composed: true event is dispatched from inside an open shadow root, dependencies that exist only in that shadow tree are invisible to document.querySelectorAll. Consequently, isOnPage(dep) returns false even for components found by the scoped mount, and a fast legacy controller runs without waiting for its slower dependency to register. Its DS.get lookup can fail, and the retained claim prevents recovery on a later event. Include components from the mounting scope or its tree when building the dependency-presence set.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
I think I'll just drop the promise of addressing legacy DS in shadow tree - for this to be an issue, it needs a legacy DS controller and its dependency to both be inside the same shadow tree and only in there.
Pages that inject server-rendered HTML later (e.g. restoring a truncated article) dispatch a clay:mount event from the container, and the bootstrap mounts the component elements at or under it. A caller that needs to wait passes an object as detail and gets a promise on detail.mounted. An event rather than a window global, so component code needs no guard in edit mode or under clay compile, where nothing listens. The listener is on window in the capture phase, so the event is caught whether or not it bubbles, and from document or window (both mean the whole page). Components inside a shadow root are not supported. Each element is mounted at most once, so repeated events are safe, and an event that overlaps another waits for the mounts that one is still running. An element whose module failed to load is released so a later event can retry it; a controller that ran and threw is not run again. Mounts under a root skip the preload pass and only walk the document when a controller has DS dependencies, so one slow chunk or a long page does not hold them up. Only the page-load run goes on the performance timeline; its mount behaves as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1e278c7 to
e723843
Compare
What this Does
Pages that inject server-rendered HTML later (e.g. restoring a truncated article) dispatch a bubbling clay:mount event from the container, and the bootstrap mounts the component elements at or under it. A caller that needs to wait passes an object as detail and gets a promise on detail.mounted.
An event rather than a window global, so component code needs no guard in edit mode or under clay compile, where nothing listens.
Each element is mounted at most once, so repeated or overlapping events are safe, and each later run gets its own performance measure. The page-load mount behaves exactly as before.
Why
The bootstrap mounts only the components that are in the DOM when it runs. Pages that add server-rendered component HTML after load had no supported way to run those components'
client.js. Examples are infinite scroll, lazy-loaded recirculation modules, server-fetched modals, and content restored after load.Where should a reviewer start?
CLAY-VITE.md, section "Mounting components added after page load: theclay:mountevent". It covers the contract: what mounts,detail.mounted, mounting at most once, the edit-mode andclay compilebehavior, and the timing.lib/cmd/vite/generate-bootstrap.js:mountComponentModules(roots): it now looks only at or under the given root, and skips elements already in themountedElsWeakSet. Called with no argument it does the same as before.clay:mountlistener at the end of the generated bootstrap.clay-components, and later runs getclay-components-2,-3, and so on.lib/cmd/vite/controller-deps.test.js,describe('the clay:mount event'), with seven tests:detailobject passeddocumentDS.getdependency outside the rootManual testing steps
In a site using
clay vite, linked to this branch:[clay vite] mounted N/M componentsas before./_components/<name>/instances/<id>.html), insert it into a container, and dispatchclay:mountfrom that container.client.jsruns, a second[clay vite] mounted …line logs only the new elements, and components already on the page are not mounted again.