Skip to content

fix(compiler-sfc): auto add nesting selector for nesting ::v-deep - #13163

Open
edison1105 wants to merge 2 commits into
mainfrom
edison/fix/deepNesting
Open

edison1105 wants to merge 2 commits into
mainfrom
edison/fix/deepNesting

Conversation

@edison1105

Copy link
Copy Markdown
Member

close #13159

@github-actions

github-actions Bot commented Apr 5, 2025

Copy link
Copy Markdown

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 100 kB 38.1 kB 34.4 kB
vue.global.prod.js 158 kB 58.3 kB 51.9 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 46.4 kB 18.2 kB 16.6 kB
createApp 54.4 kB 21.2 kB 19.4 kB
createSSRApp 58.6 kB 22.9 kB 20.9 kB
defineCustomElement 59.2 kB 22.7 kB 20.7 kB
overall 68.5 kB 26.4 kB 24 kB

@pkg-pr-new

pkg-pr-new Bot commented Apr 5, 2025 •

Copy link
Copy Markdown

Open in StackBlitz

@vue/compiler-core

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

@vue/compiler-dom

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

@vue/compiler-ssr

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

@vue/compiler-sfc

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

@vue/reactivity

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

@vue/runtime-core

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

@vue/runtime-dom

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

@vue/server-renderer

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

@vue/shared

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

vue

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

@vue/compat

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

commit: bfd11af

@edison1105
edison1105 force-pushed the edison/fix/deepNesting branch from 184da1a to ae0f685 Compare April 5, 2025 02:39
@edison1105 edison1105 changed the title fix(compiler-sfc): auto add nesting combinators for ::v-deep fix(compiler-sfc): auto add nesting selector for ::v-deep Apr 5, 2025
@edison1105 edison1105 changed the title fix(compiler-sfc): auto add nesting selector for ::v-deep fix(compiler-sfc): auto add nesting selector for nesting ::v-deep Apr 5, 2025
@edison1105
edison1105 force-pushed the edison/fix/deepNesting branch from ae0f685 to bfd11af Compare April 5, 2025 02:52
@edison1105

Copy link
Copy Markdown
Member Author

/ecosystem-ci run

@vue-bot

vue-bot commented Apr 5, 2025

Copy link
Copy Markdown
Contributor

📝 Ran ecosystem CI: Open

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

@edison1105 edison1105 added ready to merge The PR is ready to be merged. scope: sfc 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. labels Apr 5, 2025
@skirtles-code

Copy link
Copy Markdown
Contributor

I think we'd also need to consider the case where the & is inside the :deep(). e.g.:

.foo {
  .bar :deep(&) {
    color: red;
  }
}

This works on main, but it breaks with this PR due to the extra &.

The example above uses :deep(&), but the selector inside the :deep() could be something more complex, rather than just &.


I'm also wondering about media queries within the nesting. e.g.:

.foo {
  @media (screen) {
    :deep(.bar) {
      color: red;
    }
  }
}

There are quite a lot of edge cases here. Some combinations of nesting seem to work, while others don't.

I'm not sure whether this would be considered in scope for this PR, as some cases fail even without :deep().

@cchangwen

cchangwen commented Jun 8, 2025 •

Copy link
Copy Markdown

强烈建议保留 :deep inner-selector 语法,因为它更符合语言上的直觉

而 :deep(inner-selector) 多了个小括号语法,是额外的知识负担
而且需要多次看文档、踩坑,才能理解它的一些细节
比如 :deep(inner-selector) 会强制添加空格,这和 scss 的 & 语法冲突:

div:deep() {
  &:hover span { color: red; }
}

// 编译结果:
// 这里 :hover 前面多了个非预期的空格
div[data-v-2ecdb3cb] :hover span {
  color: red;
}

而 :deep 能与 scss 的 & 语法兼容,显然更灵活,
重要的是它符合直觉、容易理解:只需要把 :deep 理解成决定 [data-v-] 位置 css 伪类

div:deep {
  &:hover span { color: red; }
  ... 更多嵌套规则,也只需要在外层加一个 :deep
}

div[data-v-2ecdb3cb]:hover span {
  color: red;
}

https://github.com/orgs/vuejs/discussions/13446

@dylanmccall

Copy link
Copy Markdown

Oh, I didn't realize there was a pull request for this! I added a note over here: #13159 (comment). I'd really prefer to see Vue adhering to the CSS spec in this case, rather than deviating from it further.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. ready to merge The PR is ready to be merged. scope: sfc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CSS nesting and :deep() in scoped styles not working

5 participants