Skip to content

Load block source only when its Code panel opens - #62

Open
Floating-Y wants to merge 1 commit into
deeplethe:devfrom
Floating-Y:fix/lazy-block-sources
Open

Floating-Y wants to merge 1 commit into
deeplethe:devfrom
Floating-Y:fix/lazy-block-sources

Conversation

@Floating-Y

@Floating-Y Floating-Y commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Opening a standalone Block preview still imports every Block's raw source and transforms the entire registry, even before Code is opened.

Keep the literal metadata registry and lazy preview components lightweight. Import a separate source module only when Code opens, then load and transform that Block's files and required shared overview. Cache in-flight and successful results; remove failed requests from the cache. The Code panel shows loading/error/retry feedback and ignores results after unmount. File selection survives Preview → Code.

Preserves page-first order, displayed paths, copied contents, shared overview and its note, import rewriting, page metadata-export cleanup, preview behavior and install commands. No dependency or general loading framework added. Metadata parsing and registry generation remain unchanged.

Based on upstream dev daa7cf1 in a separate worktree; the original local route-loading branch was untouched. Checked upstream PRs: #59 separates the preview route; #32/#33 cover rewriting and metadata. None removes this eager source loading.

Validation

  • Ubuntu CI web passed for commit 082d943: locked install, both regression suites, unmodified docs generation, registry consistency, typecheck and production build.

  • node --test scripts/block-metadata.test.mjs: 8 passed.

  • node --test scripts/block-sources.test.mjs: 4 passed. Executes real transpiled modules with mocked Vite glob boundaries; covers preview without source imports, selected Block/shared files, order/paths/transformations, own Block paths, concurrent/success reuse, failure and retry. Added to existing CI.

  • npm run typecheck: passed.

  • Docs/registry generation and production build passed with temporary Windows adaptations described below. Direct node node_modules/vite/bin/vite.js build --manifest passed too.

  • registry.json, build scripts, dependencies and lockfile have no changes. Full diff and git diff --check reviewed. Commit is DCO signed off.

Production browser evidence

Served production files from fresh localhost origins with Cache-Control: no-store; recorded server requests and mapped built URLs through Vite's manifest.

  • Cold /view/sidebar-07 and initial /blocks: 0 Block raw-source requests and 0 source-loader requests.
  • Opening sidebar-07 Code: exactly its 6 files plus shared/overview.tsx; no other Block source.
  • Recursive static-import closures for the HTML entry, standalone preview and Blocks page: 0 raw chunks, no source-loader module.
  • Returned HTTP 503 once for a login raw chunk, separately for the source-loader module. Both show a local error; Retry sends a fresh request returning 200 and renders the source.
  • Delayed an own Block source by 10 seconds, switched to Preview and another category: replacement panels show no stale source. Returning and reopening Code reuses the result, with one raw request total.
  • Checked dark/light previews and sidebar interaction, file switching, overview, Copy and retained selection after reopening Code. Copied overview text exactly matches the original file with the existing CodeBlock trailing-newline handling; display comparison accounts for HTML newline normalization.

These are dependency/request observations, not measured compressed-transfer or load-time savings. No source-text byte total is presented as network savings.

Local Windows limitation

Unmodified npm run docs and npm run build were run and fail in the existing documentation generator on Windows/Node 22.15.0: CRLF heading parsing, then Windows paths producing an invalid slug. Registry generation also needs a Windows-compatible npx invocation.

For local generation/build verification only, normalized MDX line endings, temporarily normalized the slug path separator and invoked npx.cmd with a shell. Both script adaptations and content changes were restored before committing. This does not claim that the unmodified standard build passes locally; The Ubuntu CI run linked above passed the unmodified standard commands.

Firefox/Safari, physical devices, deployed compression and a before/after transfer benchmark were not tested. Do not auto-merge.

Signed-off-by: danwood <118035379+Floating-Y@users.noreply.github.com>
@Floating-Y
Floating-Y marked this pull request as ready for review October 26, 2026 13:38

This branch has not been deployed

No deployments
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