Skip to content

perf: defer optional editor, draft sync, analytics, and library menu code - #1234

Open
LadyBluenotes wants to merge 1 commit into
mainfrom
codex/defer-optional-client-code
Open

perf: defer optional editor, draft sync, analytics, and library menu code#1234
LadyBluenotes wants to merge 1 commit into
mainfrom
codex/defer-optional-client-code

Conversation

@LadyBluenotes

@LadyBluenotes LadyBluenotes commented Sep 8, 2026

Copy link
Copy Markdown
Member

Opening a local builder draft currently downloads CodeMirror and transcript sync before either is needed. The closed Libraries menu also pulls its icon map into shared startup code.

  • Load CodeMirror when its panel first becomes visible. Retain it while a CSS-hidden panel is closed.
  • Import transcript promotion on Save. Keep deterministic IDs in the lightweight project module and capture the project before awaiting the import.
  • Load the Libraries mega-menu on pointer entry or keyboard focus.
  • Queue analytics immediately, then load its provider after hydration and idle. Preserve the initial URL in an explicit page view and guard against repeated head-script execution.

Production static-import graphs, compared with 362c620f using the same build settings:

Gzip bytes Before After
Shared startup 389,632 369,006
Additional draft graph 466,214 195,790

About 291 KB gzip leaves the combined initial draft graph. This measures deferred bundle bytes, not an LCP improvement.

Validation: pnpm test passed (482 passed, one skipped), production build passed, formatting and patch checks passed. Chrome desktop/mobile checks covered cold and repeated menu opening, keyboard/link navigation, mobile overlay/back, editor loading and retained edits, local draft persistence, sign-in prompting, both legacy hash formats, and analytics hydration ordering with a stubbed provider. Existing transcript tests cover promotion and deterministic IDs; authenticated server saving was not exercised in the browser.

First use can show a loading placeholder. Analytics delivery starts later, so visits ending before initialization can be missed. Homepage media and builder SSR are outside this PR.

Summary by CodeRabbit

  • New Features

    • Added a Libraries mega-menu with categorized library links, mobile and desktop layouts, and a “Browse all libraries” option.
    • Added loading feedback while Libraries content and code editors are loading.
  • Performance

    • Libraries menus and code editors now load on demand, helping improve initial page and workbench load times.
    • Analytics loading is deferred until the page is ready and scheduled during idle time.
  • Bug Fixes

    • Improved analytics initialization and page-view tracking during navigation.

@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 1e3f0193-f7ef-4b8b-a119-e2059c425f6c

📥 Commits

Reviewing files that changed from the base of the PR and between 362c620 and fecf42f.

📒 Files selected for processing (12)
  • src/components/LibrariesMenuContent.tsx
  • src/components/Navbar.tsx
  • src/components/builder/BuilderProjectDraftPage.client.tsx
  • src/components/builder/BuilderProjectPage.client.tsx
  • src/components/examples/ExampleWorkbench.client.tsx
  • src/components/examples/LazyCodeMirrorEditor.client.tsx
  • src/routes/__root.tsx
  • src/utils/analytics/bootstrap.ts
  • src/utils/builder-project-transcript-import.client.ts
  • src/utils/builder-project.ts
  • tests/analytics-bootstrap.test.ts
  • tests/builder-project-transcript-import.test.ts
💤 Files with no reviewable changes (1)
  • src/utils/builder-project-transcript-import.client.ts

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

Changes

UI lazy loading

Layer / File(s) Summary
Lazy libraries menu
src/components/LibrariesMenuContent.tsx, src/components/Navbar.tsx
The libraries menu moves into a lazy-loaded component. Desktop loading starts on pointer entry or focus. Mobile and desktop layouts preserve category links and overlay navigation.
Lazy CodeMirror editor
src/components/examples/LazyCodeMirrorEditor.client.tsx, src/components/examples/ExampleWorkbench.client.tsx
CodeMirror loads when an editor container enters view. Both workbench editor views use the lazy component.

Analytics bootstrap

Layer / File(s) Summary
Hydration-triggered analytics loading
src/utils/analytics/bootstrap.ts, src/routes/__root.tsx, tests/analytics-bootstrap.test.ts
Analytics bootstrap logic moves to a shared utility. The root route dispatches the hydration event. Tests cover event queuing, deferred loading, duplicate handling, and timer fallback.

Builder project utilities

Layer / File(s) Summary
Promotion helper relocation
src/utils/builder-project.ts, src/utils/builder-project-transcript-import.client.ts, src/components/builder/BuilderProjectPage.client.tsx, tests/builder-project-transcript-import.test.ts
Promotion ID validation and derivation move to builder-project.ts. Callers and tests use the new exports.
Dynamic transcript promotion loading
src/components/builder/BuilderProjectDraftPage.client.tsx
The save flow captures the project before the try block and dynamically imports transcript promotion logic.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Merge Risk: ⚪ Minimal · up to fecf4

The deferred-loading changes preserve the reviewed editor, menu, analytics, and draft-save behaviors without an actionable merge risk.

Suggested reviewers: tannerlinsley

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.85% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 26 functions across 11 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main performance changes: deferring optional editor, draft synchronization, analytics, and Libraries menu code.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/defer-optional-client-code

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
tanstack-com fecf42f Commit Preview URL

Branch Preview URL
Sep 08 2026, 05:05 PM

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