🍕 Clarify _client-init.js component-mounting semantics in docs#250
Merged
Conversation
Several places in CLAY-VITE.md and BUNDLER-COMPARISON.md described the legacy Browserify component loader as "mounts every .client module loaded — no DOM check" or "DOM or not". That overstates what _client-init.js actually does. Per lib/cmd/compile/_client-init.js, mountComponentModules() iterates every .client key in window.modules and calls window.require(key) on each — which executes the module body and walks its dependency graph regardless of DOM presence — but the exported controller function is only invoked via tryToMount() for elements matching the [data-uri*="_components/<name>/"] / [data-uri$="_components<name>"] selectors. So the mount call itself IS DOM-gated; what isn't gated is module evaluation. The Vite improvement is therefore narrower but still real: vite-bootstrap scans the DOM first and skips the dynamic import() entirely if no matching element exists, so neither the module body nor any of its transitive dependencies execute. Updated all four prose locations to reflect this; the mermaid diagrams already used the more precise "calls window.require(key) for every .client / regardless of DOM presence" wording and were left as-is. Co-authored-by: Cursor <cursoragent@cursor.com>
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.
Summary
Several places in
CLAY-VITE.mdandBUNDLER-COMPARISON.mddescribed the legacy Browserify component loader as "mounts every.clientmodule loaded — no DOM check" or "DOM or not". That overstates what_client-init.jsactually does and confuses readers about the precise nature of the Vite improvement.What
_client-init.jsactually doesPer
lib/cmd/compile/_client-init.js,mountComponentModules():.clientkey inwindow.moduleswindow.require(key)on each — this executes the module body and walks its full dependency graph, regardless of DOM presencedocument.querySelectorAll([data-uri*="_components/<name>/"])and only calls the exported controller viatryToMount(controllerFn, el, name)for elements that actually existSo the mount invocation itself is DOM-gated — what isn't gated is module evaluation and dependency resolution.
What
vite-bootstrap.jsdoes (the actual improvement)Scans the DOM first and skips the dynamic
import()entirely when no matching element exists. Neither the module body nor any of its transitive dependencies execute for components absent from the page.Files changed
CLAY-VITE.md— three table cells in §4a (architecture summary), §4d (concern matrix), and §11 (clay compilevsclay vitecomparison)BUNDLER-COMPARISON.md— one inline diagram caption in §1The mermaid diagrams in
CLAY-VITE.mdandCLAYCLI-ROLLOUT-CHANGES.mdalready use the more precise "callswindow.require(key)for every.client/ regardless of DOM presence" wording and are left as-is.Follow-up
sites/CLAYCLI-ROLLOUT-CHANGES.md(innymag/sites) has the same overstated wording in its concern matrix; will be fixed in a separate sites PR.Test plan
npm test— lint + 435 jest tests pass locallyMade with Cursor