Skip to content

🍕 Improve Vite mount error diagnostics and docs#251

Merged
jjpaulino merged 2 commits into
masterfrom
jordan/fix-client-init-mounting-docs
May 28, 2026
Merged

🍕 Improve Vite mount error diagnostics and docs#251
jjpaulino merged 2 commits into
masterfrom
jordan/fix-client-init-mounting-docs

Conversation

@jjpaulino
Copy link
Copy Markdown
Member

@jjpaulino jjpaulino commented May 28, 2026

Summary

  • adds structured error reporting to generated vite-bootstrap.js for preload, load, mount, and ds-mount phases
  • logs both a concise summary table and full detailed error payloads (including component, moduleKey, uri, message, stack, and nested cause)
  • documents the new diagnostics in CLAY-VITE.md with concrete example browser console output so failures are easier to debug quickly
  • adds generator test assertions to lock the new bootstrap error-surface logs

Why

The previous mount error output only exposed terse messages and made it hard to identify where/why a component failed. This change surfaces enough context for engineers to debug directly from DevTools without digging through generated bundles.

Before vs after output

Before

[clay vite] mount errors: [
  "comments-link (load): Init must be called with `name` property",
  "article (load): Init must be called with `name` property",
  "auth-modal (mount): Cannot read properties of null (reading 'textContent')"
]

After

[clay vite] mount errors (2)
┌─────────┬──────────┬────────────────┬─────────────────────────────────────┬──────────────────────────────────────────────────────────────┬─────────────────────────────────────────────────────────────┐
│ (index) │  phase   │   component    │              moduleKey              │                             uri                              │                           message                           │
├─────────┼──────────┼────────────────┼─────────────────────────────────────┼──────────────────────────────────────────────────────────────┼─────────────────────────────────────────────────────────────┤
│    0    │ 'load'   │ 'comments-link'│ 'components/comments-link/client.js'│ '/_components/comments-link/instances/cmp123'                │ 'Init must be called with `name` property'                  │
│    1    │ 'mount'  │ 'auth-modal'   │ 'components/auth-modal/client.js'   │ '/_components/auth-modal/instances/cmp456'                   │ "Cannot read properties of null (reading 'textContent')"   │
└─────────┴──────────┴────────────────┴─────────────────────────────────────┴──────────────────────────────────────────────────────────────┴─────────────────────────────────────────────────────────────┘

[clay vite] mount error details [
  {
    phase: 'load',
    component: 'comments-link',
    moduleKey: 'components/comments-link/client.js',
    uri: '/_components/comments-link/instances/cmp123',
    error: {
      name: 'Error',
      message: 'Init must be called with `name` property',
      stack: 'Error: Init must be called with `name` property\\n    at ...'
    }
  },
  {
    phase: 'mount',
    component: 'auth-modal',
    moduleKey: 'components/auth-modal/client.js',
    uri: '/_components/auth-modal/instances/cmp456',
    error: {
      name: 'TypeError',
      message: "Cannot read properties of null (reading 'textContent')",
      stack: "TypeError: Cannot read properties of null (reading 'textContent')\\n    at ..."
    }
  }
]

Test plan

  • npx jest lib/cmd/vite/generators.test.js
  • Verified generated bootstrap includes mount error summary + detailed logs
  • Verified docs include example output for real-world failures

jjpaulino and others added 2 commits May 15, 2026 13:49
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>
Emit structured preload/load/mount error details in the generated Vite bootstrap and document concrete console output so developers can quickly identify failing component phases, URIs, and stack context.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 86.85%. remained the same — jordan/fix-client-init-mounting-docs into master

@jjpaulino jjpaulino self-assigned this May 28, 2026
@jjpaulino jjpaulino merged commit 3a5c72e into master May 28, 2026
6 checks passed
@jjpaulino jjpaulino deleted the jordan/fix-client-init-mounting-docs branch May 28, 2026 02:16
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.

2 participants