fix(runtime): avoid server-side script use callbacks - #820
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
commit: |
📝 WalkthroughWalkthrough
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
test/unit/utils.test.ts (1)
26-55: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd a direct SSR test for
useScript().Because this file mocks
packages/script/src/runtime/composables/useScript, the new guard at Line 165 inpackages/script/src/runtime/composables/useScript.tsnever runs here. A regression in the directuseScript()path would still pass this suite. Consider adding one spec that calls the real composable without that mock.🤖 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 `@test/unit/utils.test.ts` around lines 26 - 55, Add a direct SSR regression test for useScript() itself, since the current specs only exercise useRegistryScript and the mock for packages/script/src/runtime/composables/useScript bypasses the new server-side guard. Create one test that imports/calls the real useScript composable without that mock, runs it in an SSR-like context, and asserts the returned use handler is server-safe while any unsafe use callback is not invoked.
🤖 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.
Nitpick comments:
In `@test/unit/utils.test.ts`:
- Around line 26-55: Add a direct SSR regression test for useScript() itself,
since the current specs only exercise useRegistryScript and the mock for
packages/script/src/runtime/composables/useScript bypasses the new server-side
guard. Create one test that imports/calls the real useScript composable without
that mock, runs it in an SSR-like context, and asserts the returned use handler
is server-safe while any unsafe use callback is not invoked.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 593a9df7-09df-4a67-aead-29ec54660729
📒 Files selected for processing (3)
packages/script/src/runtime/composables/useScript.tspackages/script/src/runtime/utils.tstest/unit/utils.test.ts
🔗 Linked issue
Related to #815
❓ Type of change
📚 Description
scriptOptions.use()can read browser globals while Unhead builds script proxies. In SSR builds,windowcan be rewritten toundefined, so touching a registry proxy during server render can throw before hydration.This wraps
use()with a server-side noop inuseScriptanduseRegistryScript, including npm-mode scripts. The client path still gets the original callback.