-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
fix(nuxt): allow camelCase for lazy hydration attributes #32297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enables PascalCase lazy-hydration attributes alongside existing kebab-case support.
- Added tests for PascalCase lazy-hydration props
- Updated the plugin regex to recognize PascalCase variants
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
packages/nuxt/test/component-loader.test.ts | Added PascalCase entries in the lazy hydration tests |
packages/nuxt/src/components/plugins/lazy-hydration-transform.ts | Extended regex to match PascalCase hydration props |
@@ -23,7 +23,9 @@ const hydrationStrategyMap = { | |||
hydrateWhen: 'If', | |||
hydrateNever: 'Never', | |||
} | |||
const LAZY_HYDRATION_PROPS_RE = /\bhydrate-?on-?idle|hydrate-?on-?visible|hydrate-?on-?interaction|hydrate-?on-?media-?query|hydrate-?after|hydrate-?when|hydrate-?never\b/ | |||
|
|||
const LAZY_HYDRATION_PROPS_RE = /\b(?:hydrate-on-idle|HydrateOnIdle|hydrate-on-visible|HydrateOnVisible|hydrate-on-interaction|HydrateOnInteraction|hydrate-on-media-query|HydrateOnMediaQuery|hydrate-after|HydrateAfter|hydrate-when|HydrateWhen|hydrate-never|HydrateNever)\b/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The regex is quite repetitive and could become hard to maintain as strategies evolve. Consider consolidating patterns and using a case-insensitive flag with grouped alternations, for example: const LAZY_HYDRATION_PROPS_RE = /\b(?:hydrate(?:-on-(?:idle|visible|interaction|media-query)|-after|-when|-never)|Hydrate(?:On(?:Idle|Visible|Interaction|MediaQuery)|After|When|Never))\b/;
const LAZY_HYDRATION_PROPS_RE = /\b(?:hydrate-on-idle|HydrateOnIdle|hydrate-on-visible|HydrateOnVisible|hydrate-on-interaction|HydrateOnInteraction|hydrate-on-media-query|HydrateOnMediaQuery|hydrate-after|HydrateAfter|hydrate-when|HydrateWhen|hydrate-never|HydrateNever)\b/ | |
const LAZY_HYDRATION_PROPS_RE = new RegExp( | |
`\\b(?:${Object.keys(hydrationStrategyMap) | |
.map(key => key.replace(/([A-Z])/g, '-$1').toLowerCase() + '|' + key) | |
.join('|')})\\b`, | |
'i' | |
) |
Copilot uses AI. Check for mistakes.
WalkthroughThe changes update the regular expression in the lazy hydration transform logic to explicitly match hydration-related attributes in both kebab-case and camelCase forms, covering all hydration strategies such as 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/nuxt/src/components/plugins/lazy-hydration-transform.ts (1)
26-28
: Regex expanded correctly—but consider DRYing it out
The updatedLAZY_HYDRATION_PROPS_RE
now explicitly matches both kebab-case and PascalCase lazy hydration attributes as intended. To reduce duplication and avoid drift whenhydrationStrategyMap
changes in future, you could programmatically derive this pattern from the map’s keys usingkebabCase
andpascalCase
.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/nuxt/src/components/plugins/lazy-hydration-transform.ts
(1 hunks)packages/nuxt/test/component-loader.test.ts
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: build
- GitHub Check: code
🔇 Additional comments (1)
packages/nuxt/test/component-loader.test.ts (1)
133-139
: PascalCase hydration props tests added
Great addition—these parameterised tests now cover PascalCase variants and ensure they resolve to the correct lazy hydration components, matching the transform regex update.
@nuxt/kit
nuxt
@nuxt/rspack-builder
@nuxt/schema
@nuxt/vite-builder
@nuxt/webpack-builder
commit: |
CodSpeed Performance ReportMerging #32297 will not alter performanceComparing Summary
|
🔗 Linked issue
fix #32295
📚 Description
This PR allows users to use PascalCase attribute for lazy hydration