Skip to content

perf(dashmint-lab): strip SDK modulepreload + parallelize fonts#73

Merged
thephez merged 3 commits intomainfrom
feat/dashmint-lab-perf
Apr 30, 2026
Merged

perf(dashmint-lab): strip SDK modulepreload + parallelize fonts#73
thephez merged 3 commits intomainfrom
feat/dashmint-lab-perf

Conversation

@thephez
Copy link
Copy Markdown
Collaborator

@thephez thephez commented Apr 30, 2026

Vite auto-injects for every dynamic-import chunk it discovers. For the ~8MB Evo SDK that defeated the previous deferral commit — the browser raced to fetch the SDK in parallel with the entry chunk, blocking FCP. Filter it out via build.modulePreload.resolveDependencies.

Also move the Google Fonts URL out of CSS @import (which serializes the font fetch behind the stylesheet parse) and into tags in index.html with preconnect to fonts.googleapis.com / fonts.gstatic.com, so the font fetch parallelizes with the JS download.

Together with the prior dynamic-import commit, FCP drops from 5.1s to 2.7s on a localhost preview Lighthouse run.

Co-Authored-By: Claude Opus 4.7 (1M context) noreply@anthropic.com

Summary by CodeRabbit

Release Notes

  • Performance Improvements
    • Optimized font loading with preconnect configuration for faster page initialization
    • Deferred auto-connect to next animation frame for smoother app startup
    • Lazy-loaded Dash SDK module on demand
    • Optimized module preloading for Evo SDK to reduce initial bundle impact

thephez and others added 2 commits April 30, 2026 13:53
Lighthouse FCP/LCP were 5.1s/5.8s because the ~8MB evo-sdk WASM bundle
loaded synchronously at app boot. Switch SessionContext to a dynamic
import for createClient + IdentityKeyManager so Vite splits the SDK
into its own chunk that fetches after the shell paints. Auto-browse
is also deferred via requestAnimationFrame.

Split contract.ts: storage helpers (loadStoredContractId,
fetchContractOwnerId, ...) move to contractStorage.ts so SessionContext
can import them without dragging @dashevo/evo-sdk into the entry chunk.

Entry chunk drops from a single ~6MB-gzip bundle to 89KB gzip.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Vite auto-injects <link rel="modulepreload"> for every dynamic-import
chunk it discovers. For the ~8MB Evo SDK that defeated the previous
deferral commit — the browser raced to fetch the SDK in parallel with
the entry chunk, blocking FCP. Filter it out via
build.modulePreload.resolveDependencies.

Also move the Google Fonts URL out of CSS @import (which serializes
the font fetch behind the stylesheet parse) and into <link> tags in
index.html with preconnect to fonts.googleapis.com / fonts.gstatic.com,
so the font fetch parallelizes with the JS download.

Together with the prior dynamic-import commit, FCP drops from 5.1s to
2.7s on a localhost preview Lighthouse run.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 30, 2026

Warning

Rate limit exceeded

@thephez has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 47 minutes and 25 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1ac88bb5-74a3-4fc3-9510-c0de84f30a8f

📥 Commits

Reviewing files that changed from the base of the PR and between ba49a5b and ad28255.

📒 Files selected for processing (1)
  • example-apps/dashmint-lab/src/session/SessionContext.tsx
📝 Walkthrough

Walkthrough

This PR refactors contract persistence logic into a dedicated module, optimizes font loading with preconnection headers, defers browser auto-connect execution using requestAnimationFrame, switches SessionContext to dynamic imports for SDK dependencies, and configures Vite to lazy-load the Evo SDK via modulePreload customization.

Changes

Cohort / File(s) Summary
Font Loading Configuration
example-apps/dashmint-lab/index.html, example-apps/dashmint-lab/src/styles/globals.css
Adds preconnect links to Google Fonts in HTML head and removes inline @import from CSS, directing font loading to HTML <link> tags for parallelized fetching.
Contract Storage Refactoring
example-apps/dashmint-lab/src/dash/contract.ts, example-apps/dashmint-lab/src/dash/contractStorage.ts
Extracts contract ID persistence (loadStoredContractId, saveContractId, clearStoredContractId), default constant, and owner-fetching logic into new contractStorage.ts; original file now re-exports from the new module.
Dynamic SDK Imports & Session
example-apps/dashmint-lab/src/session/SessionContext.tsx, example-apps/dashmint-lab/test/SessionContext.test.tsx
Switches from static imports to cached dynamic imports for SDK client factory and IdentityKeyManager; updates contract imports to contractStorage; test mocks adjusted to match the dynamic import strategy.
Auto-Connect Timing
example-apps/dashmint-lab/src/App.tsx
Defers browseOnly() execution until the next animation frame using requestAnimationFrame when connection status is idle.
Build Configuration
example-apps/dashmint-lab/vite.config.ts
Customizes Vite modulePreload to exclude dependencies with "evo-sdk" identifier, deferring SDK preload until runtime dynamic import.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Poem

🐰 Fonts preconnect with eager ears,
Contracts tucked in storage-spheres,
Dynamic imports bound so tight,
Lazy preload sees the light—
A rabbit's code hops ever bright! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. 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 summarizes the two main performance optimizations: removing SDK modulepreload injection and parallelizing font loading through explicit link tags.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/dashmint-lab-perf

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
Review rate limit: 0/1 reviews remaining, refill in 47 minutes and 25 seconds.

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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
example-apps/dashmint-lab/src/dash/contractStorage.ts (1)

33-46: ⚡ Quick win

Add function-level JSDoc for fetchContractOwnerId.

fetchContractOwnerId is an exported async SDK operation but currently has no leading JSDoc block.

Proposed update
+/**
+ * Fetch the data contract and return its owner identity ID.
+ *
+ * SDK method: sdk.contracts.fetch(...)
+ */
 export async function fetchContractOwnerId({
   sdk,
   contractId,
 }: {
As per coding guidelines: “Dash SDK operations in src/dash/ should export async functions with leading JSDoc blocks, not hooks or wrappers — the SDK call is the function itself.”
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@example-apps/dashmint-lab/src/dash/contractStorage.ts` around lines 33 - 46,
Add a function-level JSDoc block immediately above fetchContractOwnerId
describing its purpose (fetching and normalizing a contract owner id),
parameters (sdk: DashSdk, contractId: string) and the returned value
(Promise<string | null>), and include any relevant notes about how it handles
contract.toJSON and fallback keys ($ownerId/ownerId). Ensure the JSDoc uses
standard tags (`@param`, `@returns`) and clearly states that it returns null when
the contract or owner id is not found.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@example-apps/dashmint-lab/src/session/SessionContext.tsx`:
- Around line 43-48: The dynamic import promise cached by sdkModulePromise (in
loadSdkModule) is never cleared on rejection, causing subsequent
connect()/login() attempts to immediately fail; update loadSdkModule so that
when the import promise rejects it clears sdkModulePromise (e.g., attach a
.catch handler that sets sdkModulePromise = undefined and rethrows the error) so
retries can attempt the import again.

---

Nitpick comments:
In `@example-apps/dashmint-lab/src/dash/contractStorage.ts`:
- Around line 33-46: Add a function-level JSDoc block immediately above
fetchContractOwnerId describing its purpose (fetching and normalizing a contract
owner id), parameters (sdk: DashSdk, contractId: string) and the returned value
(Promise<string | null>), and include any relevant notes about how it handles
contract.toJSON and fallback keys ($ownerId/ownerId). Ensure the JSDoc uses
standard tags (`@param`, `@returns`) and clearly states that it returns null when
the contract or owner id is not found.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4b866c2e-4943-4085-b3ac-5c8d491be53d

📥 Commits

Reviewing files that changed from the base of the PR and between ee75705 and ba49a5b.

📒 Files selected for processing (8)
  • example-apps/dashmint-lab/index.html
  • example-apps/dashmint-lab/src/App.tsx
  • example-apps/dashmint-lab/src/dash/contract.ts
  • example-apps/dashmint-lab/src/dash/contractStorage.ts
  • example-apps/dashmint-lab/src/session/SessionContext.tsx
  • example-apps/dashmint-lab/src/styles/globals.css
  • example-apps/dashmint-lab/test/SessionContext.test.tsx
  • example-apps/dashmint-lab/vite.config.ts

Comment thread example-apps/dashmint-lab/src/session/SessionContext.tsx
If the dynamic import of setupDashClient-core fails (e.g., a transient
chunk fetch failure), the rejected promise stayed cached, so every
subsequent connect/login attempt would await the same rejected promise
and fail immediately. Clear the cache on rejection so retries can
re-attempt the import.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@thephez thephez merged commit 781ef54 into main Apr 30, 2026
3 checks passed
@thephez thephez deleted the feat/dashmint-lab-perf branch April 30, 2026 18:27
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