fix: skip hydration check if client only component#227
fix: skip hydration check if client only component#227huang-julien wants to merge 1 commit intomainfrom
Conversation
commit: |
📝 WalkthroughWalkthroughThis change modifies the hydration check composable to recognize components wrapped in Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 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.
🧹 Nitpick comments (1)
src/runtime/hydration/composables.ts (1)
12-16: Move theimport.meta.serverguard before theinjectcall.
inject(clientOnlySymbol, false)is called on line 12 before the server-side early return on line 14. Sinceimport.meta.serverresolves totrueon the server build, theinjectcall executes but its result is discarded—adding unnecessary overhead. Reordering to checkimport.meta.serverfirst avoids the lookup on the server path.♻️ Proposed reorder
+ if (import.meta.server) { + return + } + const isClientOnly = inject(clientOnlySymbol, false) - if (import.meta.server || isClientOnly) { + if (isClientOnly) { return }Note: This code depends on
clientOnlySymbolbeing provided by Nuxt's<ClientOnly>component in its setup. This is an internal Nuxt implementation detail, so be aware of potential fragility if Nuxt's internal structure changes.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/runtime/hydration/composables.ts` around lines 12 - 16, Move the server-side guard to run before calling inject: check import.meta.server first and return early if true, then call inject(clientOnlySymbol, false) and proceed with the existing isClientOnly logic; this avoids invoking inject(clientOnlySymbol, false) on the server where its result is discarded.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/runtime/hydration/composables.ts`:
- Around line 12-16: Move the server-side guard to run before calling inject:
check import.meta.server first and return early if true, then call
inject(clientOnlySymbol, false) and proceed with the existing isClientOnly
logic; this avoids invoking inject(clientOnlySymbol, false) on the server where
its result is discarded.
🔗 Linked issue
fix #217
❓ Type of change
📚 Description
Check for clientonly symbol; If true, we'll skip the hydration check