Skip to content

fix(compiler-sfc): replace trailing universal selector with :where([id]) in scoped styles #13404

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

Closed
wants to merge 1 commit into from

Conversation

edison1105
Copy link
Member

@edison1105 edison1105 commented May 28, 2025

close #13401
re-fix #12906

#12918 replaced * with [id], which indirectly increased the rule's specificity
.row[data-v-e17ea971] > * {} changed to .row[data-v-e17ea971] > [data-v-e17ea971] {},
leading to the issue in #13401.

This PR changes * to :where([id]) to maintain the same specificity.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of scoped CSS for universal selectors, ensuring that attribute selectors are now wrapped in the :where() pseudo-class for more accurate and consistent styling in compiled CSS. This affects selectors such as .foo * and *:active.

Copy link

coderabbitai bot commented May 28, 2025

Walkthrough

The changes update the logic for handling trailing universal selectors (*) in scoped CSS. Now, when compiling such selectors, the scoped attribute is wrapped with the :where() pseudo-class instead of being applied directly as a descendant. Test assertions are updated to reflect this new output format.

Changes

File(s) Change Summary
packages/compiler-sfc/src/style/pluginScoped.ts Changed logic to wrap the scoped attribute selector in :where() for universal selectors in scoped CSS.
packages/compiler-sfc/tests/compileStyle.spec.ts Updated test expectations to match the new :where([data-v-*]) output for universal selectors.

Sequence Diagram(s)

sequenceDiagram
    participant Developer
    participant SFC_Compiler
    participant CSS_Parser

    Developer->>SFC_Compiler: Write CSS with universal selectors in .vue file
    SFC_Compiler->>CSS_Parser: Parse CSS selectors
    CSS_Parser-->>SFC_Compiler: Return selector AST
    SFC_Compiler->>SFC_Compiler: Detect trailing universal selector
    SFC_Compiler->>SFC_Compiler: Replace with :where([data-v-xxx])
    SFC_Compiler-->>Developer: Output compiled CSS with :where([data-v-xxx])
Loading

Assessment against linked issues

Objective Addressed Explanation
Fix scoped CSS rewriting so that Bootstrap 5 grid system works as expected (#13401)

Possibly related PRs

Suggested labels

ready to merge, scope: sfc, :hammer: p3-minor-bug

Poem

A rabbit hopped through fields of code,
Where universal stars once glowed.
Now wrapped in :where(), selectors prance,
Ensuring grids and rows can dance.
With every hop and little tweak,
CSS behaves just as we seek!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d9bd436 and a153f22.

📒 Files selected for processing (2)
  • packages/compiler-sfc/__tests__/compileStyle.spec.ts (3 hunks)
  • packages/compiler-sfc/src/style/pluginScoped.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Redirect rules
  • GitHub Check: Header rules
  • GitHub Check: Pages changed
🔇 Additional comments (7)
packages/compiler-sfc/src/style/pluginScoped.ts (3)

221-221: Good documentation update.

The comment accurately reflects the new behavior of wrapping the scoped attribute in :where().


283-283: Comment correctly updated to match implementation.

The updated comment accurately describes the new output pattern.


287-297:

❓ Verification inconclusive

Verify browser compatibility and specificity implications of :where() usage.

The implementation correctly wraps the scoped attribute selector in a :where() pseudo-class, but this introduces important considerations:

  1. Browser Support: :where() is supported in Chrome 88+, Firefox 78+, Safari 14+. This could break compatibility with older browsers.
  2. CSS Specificity: :where() has 0 specificity, unlike attribute selectors. This could affect style precedence in existing applications.

Please verify:

  1. Browser compatibility requirements for the target applications
  2. Impact assessment of specificity changes on existing codebases

🌐 Web query:

What is the browser support for CSS :where() pseudo-class and what is its specificity?

💡 Result:

The CSS :where() pseudo-class is supported in the major modern browsers including:

  • Chrome (since version 88)
  • Firefox (since version 78)
  • Safari (since version 14.1)
  • Edge (Chromium-based, since version 88)

It may not be supported in older browsers or versions predating these releases.

Regarding specificity, the :where() pseudo-class is unique because it has a specificity of zero. This means selectors inside :where() do not contribute to the overall specificity of the selector using it. This makes :where() useful for applying styles without affecting specificity-based conflicts.

Would you like me to confirm or fetch the latest browser versions to verify this?


Confirm browser support and specificity impact of :where()

The CSS :where() pseudo-class used here (packages/compiler-sfc/src/style/pluginScoped.ts lines 287–297) has zero specificity and is supported only in modern browsers:

  • Chrome ≥ 88
  • Firefox ≥ 78
  • Safari ≥ 14.1
  • Edge (Chromium) ≥ 88
  • Not supported in IE or older browser versions

Please verify:

  • That your target applications’ browser requirements align with these minimum versions (or provide a fallback for unsupported browsers).
  • That using :where([scoped-id]) doesn’t unintentionally alter style precedence in your existing stylesheets.
packages/compiler-sfc/__tests__/compileStyle.spec.ts (4)

496-496: Test expectation correctly updated for universal selector handling.

The test now expects .foo[data-v-test] :where([data-v-test]) which matches the new implementation behavior.


506-506: Test correctly handles universal selector with pseudo-class.

The expectation .foo[data-v-test] :where([data-v-test]):active properly shows that pseudo-classes are applied after the :where() wrapper.


515-515: Test properly handles pseudo-class followed by universal selector.

The pattern [data-v-test]:last-child :where([data-v-test]) correctly demonstrates the scoped attribute application order.


520-520: Test correctly combines all selector patterns.

The expectation [data-v-test]:last-child :where([data-v-test]):active properly shows the complete pattern with pseudo-classes before and after the :where() wrapper.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 101 kB 38.3 kB 34.5 kB
vue.global.prod.js 159 kB 58.5 kB 52 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 46.6 kB 18.2 kB 16.7 kB
createApp 54.5 kB 21.2 kB 19.4 kB
createSSRApp 58.8 kB 23 kB 20.9 kB
defineCustomElement 59.5 kB 22.8 kB 20.8 kB
overall 68.6 kB 26.4 kB 24 kB

Copy link

pkg-pr-new bot commented May 28, 2025

Open in StackBlitz

@vue/compiler-core

npm i https://pkg.pr.new/@vue/compiler-core@13404

@vue/compiler-dom

npm i https://pkg.pr.new/@vue/compiler-dom@13404

@vue/compiler-sfc

npm i https://pkg.pr.new/@vue/compiler-sfc@13404

@vue/compiler-ssr

npm i https://pkg.pr.new/@vue/compiler-ssr@13404

@vue/reactivity

npm i https://pkg.pr.new/@vue/reactivity@13404

@vue/runtime-core

npm i https://pkg.pr.new/@vue/runtime-core@13404

@vue/runtime-dom

npm i https://pkg.pr.new/@vue/runtime-dom@13404

@vue/server-renderer

npm i https://pkg.pr.new/@vue/server-renderer@13404

@vue/shared

npm i https://pkg.pr.new/@vue/shared@13404

vue

npm i https://pkg.pr.new/vue@13404

@vue/compat

npm i https://pkg.pr.new/@vue/compat@13404

commit: a153f22

@edison1105 edison1105 changed the title fix(compiler-sfc): replace universal selector with :where([id]) in scoped styles fix(compiler-sfc): replace trailing universal selector with :where([id]) in scoped styles May 28, 2025
@edison1105
Copy link
Member Author

/ecosystem-ci run

@Justineo
Copy link
Member

This could lead to browser compatibility issues.

https://vuejs.org/about/faq.html#what-browsers-does-vue-support

@edison1105 edison1105 marked this pull request as draft May 28, 2025 23:57
@vue-bot
Copy link
Contributor

vue-bot commented May 29, 2025

📝 Ran ecosystem CI: Open

suite result latest scheduled
language-tools success success
radix-vue success success
vant success success
quasar success success
router success success
vue-macros success success
pinia success success
primevue success success
vuetify success success
test-utils success success
vue-simple-compiler success success
vite-plugin-vue success success
vue-i18n success success
vitepress success success
vueuse success success
nuxt success success

@edison1105 edison1105 closed this May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Star selectors leak scoped styles into children With Vue 3.5.15, bootstrap5 and sass, grid system does not work properly
3 participants