feat: ref/reactive outside vue/nuxtApp context detection#89
feat: ref/reactive outside vue/nuxtApp context detection#89huang-julien wants to merge 7 commits intomainfrom
Conversation
commit: |
📝 WalkthroughWalkthroughThis pull request adds server-side detection for Vue composition API functions to prevent misuse in server contexts. It introduces three components: a new runtime composables file that wraps Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 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.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/module.ts`:
- Around line 56-62: The import paths used in the addImports call are incorrect:
locate the addImports([...]) block (the entries adding 'ref', 'shallowRef',
'reactive', 'shallowReactive') and update each resolver.resolve call to include
the missing core segment in the module path (i.e., change
"./runtime/composables/vue" to "./runtime/core/composables/vue") so
resolver.resolve points to the actual implementation; keep the same import names
and structure.
| // Imports for server side misusage detection | ||
| addImports([ | ||
| { from: resolver.resolve('./runtime/composables/vue'), name: 'ref' }, | ||
| { from: resolver.resolve('./runtime/composables/vue'), name: 'shallowRef' }, | ||
| { from: resolver.resolve('./runtime/composables/vue'), name: 'reactive' }, | ||
| { from: resolver.resolve('./runtime/composables/vue'), name: 'shallowReactive' }, | ||
| ]) |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Verify the actual file paths for vue composables
echo "=== Searching for vue.ts composables file in src/runtime ==="
fd -t f 'vue.ts' src/runtime
echo -e "\n=== Checking if ./runtime/composables/vue.ts exists ==="
ls -la src/runtime/composables/vue.ts 2>/dev/null || echo "File NOT found at src/runtime/composables/vue.ts"
echo -e "\n=== Checking if ./runtime/core/composables/vue.ts exists ==="
ls -la src/runtime/core/composables/vue.ts 2>/dev/null || echo "File NOT found at src/runtime/core/composables/vue.ts"
echo -e "\n=== Listing all files in src/runtime ==="
find src/runtime -type f -name '*.ts' | head -20Repository: nuxt/hints
Length of output: 1037
Path mismatch: resolver path doesn't match actual file location.
The addImports call references './runtime/composables/vue', but the actual implementation is at src/runtime/core/composables/vue.ts. The path is missing the core/ segment, which will cause the imports to fail at runtime.
🐛 Proposed fix for path
// Imports for server side misusage detection
addImports([
- { from: resolver.resolve('./runtime/composables/vue'), name: 'ref' },
- { from: resolver.resolve('./runtime/composables/vue'), name: 'shallowRef' },
- { from: resolver.resolve('./runtime/composables/vue'), name: 'reactive' },
- { from: resolver.resolve('./runtime/composables/vue'), name: 'shallowReactive' },
+ { from: resolver.resolve('./runtime/core/composables/vue'), name: 'ref' },
+ { from: resolver.resolve('./runtime/core/composables/vue'), name: 'shallowRef' },
+ { from: resolver.resolve('./runtime/core/composables/vue'), name: 'reactive' },
+ { from: resolver.resolve('./runtime/core/composables/vue'), name: 'shallowReactive' },
])📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| // Imports for server side misusage detection | |
| addImports([ | |
| { from: resolver.resolve('./runtime/composables/vue'), name: 'ref' }, | |
| { from: resolver.resolve('./runtime/composables/vue'), name: 'shallowRef' }, | |
| { from: resolver.resolve('./runtime/composables/vue'), name: 'reactive' }, | |
| { from: resolver.resolve('./runtime/composables/vue'), name: 'shallowReactive' }, | |
| ]) | |
| // Imports for server side misusage detection | |
| addImports([ | |
| { from: resolver.resolve('./runtime/core/composables/vue'), name: 'ref' }, | |
| { from: resolver.resolve('./runtime/core/composables/vue'), name: 'shallowRef' }, | |
| { from: resolver.resolve('./runtime/core/composables/vue'), name: 'reactive' }, | |
| { from: resolver.resolve('./runtime/core/composables/vue'), name: 'shallowReactive' }, | |
| ]) |
🤖 Prompt for AI Agents
In `@src/module.ts` around lines 56 - 62, The import paths used in the addImports
call are incorrect: locate the addImports([...]) block (the entries adding
'ref', 'shallowRef', 'reactive', 'shallowReactive') and update each
resolver.resolve call to include the missing core segment in the module path
(i.e., change "./runtime/composables/vue" to "./runtime/core/composables/vue")
so resolver.resolve points to the actual implementation; keep the same import
names and structure.
🔗 Linked issue
resolve #29
❓ Type of change
📚 Description
@danielroe any opinion about this ?