core icon indicating copy to clipboard operation
core copied to clipboard

feat(compiler-sfc): support use global style in nested css

Open zh-lx opened this issue 1 year ago • 1 comments

close #10403

// scss
:global(.foo) {
    color: red;
    .bar {
        color: blue;
    }
}

The above scss code will be compiled to:

// css
:global(.foo) {
  color: red;
}
:global(.foo) .bar {
  color: blue;
}

So we should support transforming :global(.foo) .bar to .foo .bar

zh-lx avatar Mar 01 '24 06:03 zh-lx

Size Report

Bundles

File Size Gzip Brotli
runtime-dom.global.prod.js 90.5 kB 34.4 kB 31 kB
vue.global.prod.js 148 kB 53.7 kB 47.9 kB

Usages

Name Size Gzip Brotli
createApp 50.7 kB 19.8 kB 18.1 kB
createSSRApp 54.1 kB 21.1 kB 19.3 kB
defineCustomElement 53 kB 20.6 kB 18.7 kB
overall 64.4 kB 24.8 kB 22.5 kB

github-actions[bot] avatar Mar 01 '24 06:03 github-actions[bot]

In my opinion, the :global should not carry over to the child selectors.

Case 1:

:global(.foo) {
  .bar {}
}

With scss this will be translated to :global(.foo) .bar, which I think Vue should compile down to .foo .bar[data-v-123].

Case 2:

:global(.foo) {
  :global(.bar) {}
}

With scss this will be translated to :global(.foo) :global(.bar), which I think Vue should compile down to .foo .bar.

Here are a couple of SFC Playground examples based on these two cases. They are using native browser CSS nesting, not scss, but they are working the way I'd expect:

I think the target should be for scss to work the same way.

skirtles-code avatar Apr 20 '24 00:04 skirtles-code

I don't think so. In Vue, :deep() will have an effect on the sub selector. So :global() should also maintain consistency.

---- Replied Message ---- | From | @.> | | Date | 04/20/2024 08:18 | | To | @.> | | Cc | @.>@.> | | Subject | Re: [vuejs/core] feat(compiler-sfc): support use global style in nested css (PR #10436) |

In my opinion, the :global should not carry over to the child selectors.

Case 1:

:global(.foo) { .bar {} }

With scss this will be translated to :global(.foo) .bar, which I think Vue should compile down to .foo .bar[data-v-123].

Case 2:

:global(.foo) { :global(.bar) {} }

With scss this will be translated to :global(.foo) :global(.bar), which I think Vue should compile down to .foo .bar.

Here are a couple of SFC Playground examples based on these two cases. They are using native browser CSS nesting, not scss, but they are working the way I'd expect:

Case 1 Case 2

I think the target should be for scss to work the same way.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

zh-lx avatar Apr 21 '24 04:04 zh-lx

I don't think so. In Vue, :deep() will have an effect on the sub selector. So :global() should also maintain consistency. … ---- Replied Message ---- | From | @.> | | Date | 04/20/2024 08:18 | | To | @.> | | Cc | @.>@.> | | Subject | Re: [vuejs/core] feat(compiler-sfc): support use global style in nested css (PR #10436) | In my opinion, the :global should not carry over to the child selectors. Case 1: :global(.foo) { .bar {} } With scss this will be translated to :global(.foo) .bar, which I think Vue should compile down to .foo .bar[data-v-123]. Case 2: :global(.foo) { :global(.bar) {} } With scss this will be translated to :global(.foo) :global(.bar), which I think Vue should compile down to .foo .bar. Here are a couple of SFC Playground examples based on these two cases. They are using native browser CSS nesting, not scss, but they are working the way I'd expect: Case 1 Case 2 I think the target should be for scss to work the same way. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

But the proposal looks sick. Would love to have like :root selector (with line in @at-root) to keep scope

daniluk4000 avatar Apr 21 '24 13:04 daniluk4000

In my opinion, the :global should not carry over to the child selectors.

Case 1:

:global(.foo) {
  .bar {}
}

With scss this will be translated to :global(.foo) .bar, which I think Vue should compile down to .foo .bar[data-v-123].

Case 2:

:global(.foo) {
  :global(.bar) {}
}

With scss this will be translated to :global(.foo) :global(.bar), which I think Vue should compile down to .foo .bar.

Here are a couple of SFC Playground examples based on these two cases. They are using native browser CSS nesting, not scss, but they are working the way I'd expect:

I think the target should be for scss to work the same way.

I don't think so. In Vue, :deep() will have an effect on the sub selector. So :global() should also maintain consistency. … ---- Replied Message ---- | From | @.> | | Date | 04/20/2024 08:18 | | To | _@**._> | | Cc | _@.>@._> | | Subject | Re: [vuejs/core] feat(compiler-sfc): support use global style in nested css (PR #10436) | In my opinion, the :global should not carry over to the child selectors. Case 1: :global(.foo) { .bar {} } With scss this will be translated to :global(.foo) .bar, which I think Vue should compile down to .foo .bar[data-v-123]. Case 2: :global(.foo) { :global(.bar) {} } With scss this will be translated to :global(.foo) :global(.bar), which I think Vue should compile down to .foo .bar. Here are a couple of SFC Playground examples based on these two cases. They are using native browser CSS nesting, not scss, but they are working the way I'd expect: Case 1 Case 2 I think the target should be for scss to work the same way. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: _@_.*>

But the proposal looks sick. Would love to have like :root selector (with line in @at-root) to keep scope

I don't think it's necessary. If we want to add scoped to child selectors, why do the parent selectors still use :global()?

zh-lx avatar Apr 22 '24 01:04 zh-lx

I don't think it's necessary. If we want to add scoped to child selectors, why do the parent selectors still use :global()?

It's not my case. For example, we have global class on html and want to rely on it in children component without losing scoped.

daniluk4000 avatar Apr 22 '24 09:04 daniluk4000

I agree with @skirtles-code here - this change essentially makes the :global() work like a combinator instead of a functional pseudo class.

The combinator-like behavior of :deep has been deprecated for a long time and is no longer recommended, so the behavior should not apply to :global.

yyx990803 avatar Jul 11 '24 09:07 yyx990803