Skip to content

fix: provide SpeedCurve snippet fallback#811

Merged
harlan-zw merged 1 commit into
nuxt:mainfrom
sjh9714:fix-speedcurve-unregistered-snippet
Jun 2, 2026
Merged

fix: provide SpeedCurve snippet fallback#811
harlan-zw merged 1 commit into
nuxt:mainfrom
sjh9714:fix-speedcurve-unregistered-snippet

Conversation

@sjh9714
Copy link
Copy Markdown
Contributor

@sjh9714 sjh9714 commented Jun 2, 2026

Summary

Fixes #810.

useScriptSpeedCurve can now be imported in apps that have not registered scripts.registry.speedcurve because the module always emits #build/nuxt-scripts-speedcurve-snippet. Unregistered apps get an empty primer fallback; registered apps still resolve @speedcurve/lux and keep the install hint if it is missing.

Changes

  • Emit the SpeedCurve snippet virtual module unconditionally, with an empty fallback when SpeedCurve is not registered.
  • Skip primer injection when the generated snippet source is empty.
  • Add a basic fixture page that uses useScriptSpeedCurve without registry config.
  • Update the SpeedCurve setup docs to match the fallback behavior.

Testing

  • pnpm install --frozen-lockfile
  • pnpm --filter @nuxt/scripts dev:prepare
  • pnpm exec nuxt prepare
  • pnpm exec nuxt build test/fixtures/basic (failed before the fix with unresolved nuxt-scripts-speedcurve-snippet; passes after)
  • pnpm exec vitest run --project unit test/unit/speedcurve-primer.test.ts test/unit/speedcurve-config.test.ts test/unit/speedcurve-auto-tracker.test.ts
  • pnpm exec eslint packages/script/src/module.ts packages/script/src/runtime/registry/speedcurve.ts --max-warnings=0

Verification gap: pnpm exec nuxt build test/fixtures/speedcurve reached client/server/Nitro build, then failed with a local macOS ENAMETOOLONG scanning Nitro output under this long workspace path.

Note: I used Codex while preparing this change, reviewed the final diff, and ran the listed checks locally.

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Jun 2, 2026

@sjh9714 is attempting to deploy a commit to the Nuxt Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 2, 2026

Review Change Stack

📝 Walkthrough

Walkthrough

This PR resolves a build failure where unregistered SpeedCurve configuration caused the runtime to import a non-existent virtual module. The fix ensures the virtual module always emits: with empty content when SpeedCurve is unregistered, or with actual LUX snippet when registered. A runtime guard prevents initialization if the snippet is missing. Documentation now reflects the opt-in behavior and new fallback strategy. A test fixture validates behavior in the unregistered scenario.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: providing a fallback for the SpeedCurve snippet module to fix build failures.
Description check ✅ Passed The description is clearly related to the changeset, explaining the fix for issue #810, the changes made, and testing performed.
Linked Issues check ✅ Passed The pull request fully addresses issue #810 by implementing the first proposed remedy: always emitting the virtual snippet module with an empty fallback when SpeedCurve is not registered.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the SpeedCurve build failure: virtual module emission, runtime checks, test fixture, and documentation updates align with the stated objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/script/src/runtime/registry/speedcurve.ts (1)

5-11: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Update outdated comment to reflect new fallback behavior.

The comment states that non-registered users "hit a build error from the unresolved virtual," but after this PR the virtual module is always emitted with an empty fallback. The comment should reflect the current behavior.

📝 Proposed update
-// Virtual: emitted by the Nuxt module only when `speedcurve` is registered in
-// `scripts.registry`. Contents inline the LUX primer resolved from the
-// user-installed `@speedcurve/lux` peer dep at build time. Non-registered
-// users hit a build error from the unresolved virtual; registered users
-// without the peer dep get an install hint when the export is read.
+// Virtual: always emitted by the Nuxt module. When `speedcurve` is registered
+// in `scripts.registry`, contents inline the LUX primer resolved from the
+// user-installed `@speedcurve/lux` peer dep at build time. When unregistered,
+// exports an empty string fallback. Registered users without the peer dep get
+// a build error with an install hint.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/script/src/runtime/registry/speedcurve.ts` around lines 5 - 11,
Update the top-of-file comment in
packages/script/src/runtime/registry/speedcurve.ts to reflect that the virtual
module '`#build/nuxt-scripts-speedcurve-snippet`' is always emitted and now
provides an empty fallback when the peer dependency is missing (so
non-registered users no longer get a build error); locate the comment block
above the import of luxSnippetSource and replace the sentence claiming
non-registered users "hit a build error from the unresolved virtual" with text
stating the virtual is always emitted with an empty fallback and registered
users without the peer dep receive an install hint when the export is read.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@packages/script/src/runtime/registry/speedcurve.ts`:
- Around line 5-11: Update the top-of-file comment in
packages/script/src/runtime/registry/speedcurve.ts to reflect that the virtual
module '`#build/nuxt-scripts-speedcurve-snippet`' is always emitted and now
provides an empty fallback when the peer dependency is missing (so
non-registered users no longer get a build error); locate the comment block
above the import of luxSnippetSource and replace the sentence claiming
non-registered users "hit a build error from the unresolved virtual" with text
stating the virtual is always emitted with an empty fallback and registered
users without the peer dep receive an install hint when the export is read.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2952dc96-9415-4452-b14c-2e65641b174a

📥 Commits

Reviewing files that changed from the base of the PR and between bc87bf3 and c3fadf3.

📒 Files selected for processing (4)
  • docs/content/scripts/speedcurve.md
  • packages/script/src/module.ts
  • packages/script/src/runtime/registry/speedcurve.ts
  • test/fixtures/basic/pages/tpc/speedcurve-unregistered.vue

@harlan-zw harlan-zw merged commit c132279 into nuxt:main Jun 2, 2026
8 of 10 checks passed
@harlan-zw
Copy link
Copy Markdown
Collaborator

Thanks :)

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.

Nuxt build fails due to missing SpeedCurve snippet module

2 participants