Skip to content

fix(compiler-sfc): scope nested deep selector (fix #13159) - #14940

Closed
ifer47 wants to merge 1 commit into
vuejs:mainfrom
ifer47:fix-sfc-nested-deep-scope
Closed

ifer47 wants to merge 1 commit into
vuejs:mainfrom
ifer47:fix-sfc-nested-deep-scope

Conversation

@ifer47

@ifer47 ifer47 commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

Description

Fixes scoped CSS output for nested standalone :deep() selectors. When :deep() appears inside a CSS nesting rule, the generated scope attribute needs to be anchored to the parent selector with &; otherwise the compiled selector becomes [data-v-*] .foo inside the nested block and scopes the wrong element.

Test

  • pnpm run test-unit compiler-sfc --run
  • pnpm run check

Summary by CodeRabbit

  • Bug Fixes

    • Improved scoped CSS selector processing for :deep() pseudo-elements to ensure correct nesting behavior and proper anchor positioning.
  • Tests

    • Extended test coverage for :deep() syntax in scoped CSS styling.

@coderabbitai

coderabbitai Bot commented Jun 8, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cec3efc0-e9e5-4740-bd48-d981406e62ba

📥 Commits

Reviewing files that changed from the base of the PR and between 48ad452 and 81558d0.

📒 Files selected for processing (2)
  • packages/compiler-sfc/__tests__/compileStyle.spec.ts
  • packages/compiler-sfc/src/style/pluginScoped.ts

📝 Walkthrough

Walkthrough

This PR fixes issue #13159 by modifying how deep scoped selectors are rewritten in SFC compilation. When a deep selector lacks a scope node and its parent is a rule, a nesting anchor is prepended before attribute injection. The fix is validated with a regression test.

Changes

Scoped CSS Deep Selector Nesting

Layer / File(s) Summary
Nesting anchor injection for deep selectors
packages/compiler-sfc/src/style/pluginScoped.ts
In rewriteSelector, when processing a deep selector without an existing scope node under a rule parent, a selectorParser.nesting() node is prepended to correctly anchor the subsequent attribute selector injection.
Regression test for :deep() with wrapper
packages/compiler-sfc/__tests__/compileStyle.spec.ts
Test case compiles :deep(.foo) inside .base wrapper and validates the generated scoped CSS output via inline snapshot assertion.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Possibly related PRs

  • vuejs/core#14725: Modifies pluginScoped.ts to change how scoped :deep() is rewritten and injects correct nesting anchors when resolving deep selectors; both PRs extend compileStyle.spec.ts with :deep() selector-scoping test coverage.
  • vuejs/core#12918: Adjusts scoped attribute selector injection in pluginScoped.ts during selector rewriting, overlapping with the same scoped CSS selector-injection pipeline.

Suggested labels

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

Suggested reviewers

  • edison1105
  • Doctor-wu

Poem

A rabbit hops through selector trees,
With :deep() fixes sure to please,
Nesting anchors now in place,
Scoped styles find their rightful space. 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: fixing scoped CSS for nested deep selectors in the compiler-sfc package, directly addressing issue #13159.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 106 kB 40.1 kB 36 kB
vue.global.prod.js 164 kB 60.1 kB 53.5 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 48.8 kB 19 kB 17.4 kB
createApp 56.9 kB 22 kB 20.1 kB
createSSRApp 61.2 kB 23.8 kB 21.7 kB
defineCustomElement 63.1 kB 23.9 kB 21.8 kB
overall 71.7 kB 27.4 kB 25 kB

@pkg-pr-new

pkg-pr-new Bot commented Jun 8, 2026

Copy link
Copy Markdown

Open in StackBlitz

@vue/compiler-core

pnpm add https://pkg.pr.new/@vue/compiler-core@14940
npm i https://pkg.pr.new/@vue/compiler-core@14940
yarn add https://pkg.pr.new/@vue/compiler-core@14940.tgz

@vue/compiler-dom

pnpm add https://pkg.pr.new/@vue/compiler-dom@14940
npm i https://pkg.pr.new/@vue/compiler-dom@14940
yarn add https://pkg.pr.new/@vue/compiler-dom@14940.tgz

@vue/compiler-sfc

pnpm add https://pkg.pr.new/@vue/compiler-sfc@14940
npm i https://pkg.pr.new/@vue/compiler-sfc@14940
yarn add https://pkg.pr.new/@vue/compiler-sfc@14940.tgz

@vue/compiler-ssr

pnpm add https://pkg.pr.new/@vue/compiler-ssr@14940
npm i https://pkg.pr.new/@vue/compiler-ssr@14940
yarn add https://pkg.pr.new/@vue/compiler-ssr@14940.tgz

@vue/reactivity

pnpm add https://pkg.pr.new/@vue/reactivity@14940
npm i https://pkg.pr.new/@vue/reactivity@14940
yarn add https://pkg.pr.new/@vue/reactivity@14940.tgz

@vue/runtime-core

pnpm add https://pkg.pr.new/@vue/runtime-core@14940
npm i https://pkg.pr.new/@vue/runtime-core@14940
yarn add https://pkg.pr.new/@vue/runtime-core@14940.tgz

@vue/runtime-dom

pnpm add https://pkg.pr.new/@vue/runtime-dom@14940
npm i https://pkg.pr.new/@vue/runtime-dom@14940
yarn add https://pkg.pr.new/@vue/runtime-dom@14940.tgz

@vue/server-renderer

pnpm add https://pkg.pr.new/@vue/server-renderer@14940
npm i https://pkg.pr.new/@vue/server-renderer@14940
yarn add https://pkg.pr.new/@vue/server-renderer@14940.tgz

@vue/shared

pnpm add https://pkg.pr.new/@vue/shared@14940
npm i https://pkg.pr.new/@vue/shared@14940
yarn add https://pkg.pr.new/@vue/shared@14940.tgz

vue

pnpm add https://pkg.pr.new/vue@14940
npm i https://pkg.pr.new/vue@14940
yarn add https://pkg.pr.new/vue@14940.tgz

@vue/compat

pnpm add https://pkg.pr.new/@vue/compat@14940
npm i https://pkg.pr.new/@vue/compat@14940
yarn add https://pkg.pr.new/@vue/compat@14940.tgz

commit: 81558d0

@edison1105

Copy link
Copy Markdown
Member

duplicate of #13163

@edison1105 edison1105 closed this Jun 8, 2026
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.

2 participants