-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
fix(compiler-sfc): prefix digit css custom properties #13870
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughProduction-only CSS var name generation now prefixes a leading digit with "v" to comply with CSS rules. Tests updated to expect "v"-prefixed hashes in prod mode; non-prod behavior unchanged. Changes
Sequence Diagram(s)sequenceDiagram
participant SFC as SFC Compiler
participant CSSV as genVarName (prod)
participant OUT as Output CSS/JS
SFC->>CSSV: request variable name (id, raw)
note over CSSV: hash = hash(id+raw)
CSSV->>CSSV: if hash starts with digit<br/>prefix with "v"
CSSV-->>SFC: sanitized name (e.g., v4003f1a6)
SFC->>OUT: emit var(--v4003f1a6) and _useCssVars mapping
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Suggested reviewers
Pre-merge checks (2 passed, 1 warning)❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Poem
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal). Please share your feedback with us on this Discord post. ✨ Finishing touches
🧪 Generate 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. Comment |
Size ReportBundles
Usages
|
@vue/compiler-core
@vue/compiler-dom
@vue/compiler-sfc
@vue/compiler-ssr
@vue/reactivity
@vue/runtime-core
@vue/runtime-dom
@vue/server-renderer
@vue/shared
vue
@vue/compat
commit: |
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 (2)
packages/compiler-sfc/src/style/cssVars.ts (1)
43-44
: Minor: avoid regex for single-char check.Tiny micro-opt/readability; equivalent behavior without a regex.
- return hash(id + raw).replace(/^\d/, r => `v${r}`) + const h = hash(id + raw) + return h.charCodeAt(0) >= 48 && h.charCodeAt(0) <= 57 ? `v${h}` : hpackages/compiler-sfc/__tests__/cssVars.spec.ts (1)
112-114
: Tests correctly updated for prefixed prod vars.Assertions now expect var names with a leading 'v' and match the implementation.
Consider adding a small sanity check that a non-digit-leading hash remains unchanged (guard against accidental double-prefixing).
Also applies to: 127-128
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
packages/compiler-sfc/__tests__/cssVars.spec.ts
(2 hunks)packages/compiler-sfc/src/style/cssVars.ts
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Redirect rules
- GitHub Check: Header rules
- GitHub Check: Pages changed
🔇 Additional comments (1)
packages/compiler-sfc/src/style/cssVars.ts (1)
43-44
: Compliant var naming for prod — LGTM.Prefixing digit-starting hashes fixes invalid custom property idents. Change is minimal and scoped to prod path.
Hi! Thanks a lot for creating this PR 🙏 |
reported in nuxt/nuxt#33208
in short, custom properties must not start with an unescaped digit, as they are a more specialised form of
<ident>
(docs).Summary by CodeRabbit
Bug Fixes
Tests