Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a big refactor regarding SFC scoped ID for
:slotted
selectors. The original goal was to fix #2892, however in the process I realized the previous:slotted
implementation was seriously flawed which led to this massive refactor. It does not contain any breaking behavior, however due to how substantial it is, it's submitted as a PR to explicitly document the internal changes.Compiler-generated code for scope ID is in general simplified. Instead of generating a
withId
helper and wrapping every slot function with it,withCtx
is now used in all cases. Tracking the slot's owner component also tracks its scope id so there no need to use different helpers anymore.New slotted scope ID handling:
Compiler-generate slot outlets (i.e.
<slot/>
) now generate code that passes an additional boolean argument torenderSlot
. This boolean argument indicates whether the current template belongs to an SFC that also has:slotted
selectors.When rendering the slot fragment, if the owner component uses
:slotted
, the fragment vnode gets assigned aslotScopeIds
array.In the patch phase, when encountering a fragment with non-null
slotScopeIds
, we now know this is a slot whose content needs the slotted scope attributes (data-v-xxxxxxxx-s
).This does require passing down
slotScopeIds
as an argument through almost all renderer functions, similar toisSVG
andoptimized
. I did try refactoring it to a context instead, however the patch context refactor is very risky: it broke e2e test cases while passing all unit tests, and the end bundle size got bigger, so I ended up sticking with the argument passing.SSR handling of scope ID is updated accordingly.
Optimization: slot scope IDs only need to be applied if the component actually uses
:slotted
styles.@vue/compiler-dom
and@vue/compiler-ssr
now both accepted aslotted
option. This option istrue
by default to retain backwards compatibility.@vue/compiler-sfc
SFCDescriptor
now exposes aslotted
property which indicates whether the component uses:slotted
styles.compileTemplate
now accepts aslotted
option which is passed on to@vue/compiler-dom
and@vue/compiler-ssr
. Higher level tools (e.g.vite
orvue-loader
) should be updated to pass the descriptor'sslotted
property tocompileTemplate
to enable the optimization.