Skip to content

Commit f596e00

Browse files
committed
refactor: remove deprecated scopeId codegen
BREAKING CHANGE: Output of SFC using `<style scoped>` generated by 3.2+ will be incompatible w/ runtime <3.2.
1 parent 1c7d737 commit f596e00

File tree

7 files changed

+12
-82
lines changed

7 files changed

+12
-82
lines changed

packages/compiler-core/__tests__/__snapshots__/scopeId.spec.ts.snap

+4-8
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
exports[`scopeId compiler support should push scopeId for hoisted nodes 1`] = `
44
"import { createElementVNode as _createElementVNode, toDisplayString as _toDisplayString, createTextVNode as _createTextVNode, openBlock as _openBlock, createElementBlock as _createElementBlock, withScopeId as _withScopeId, pushScopeId as _pushScopeId, popScopeId as _popScopeId } from \\"vue\\"
5-
const _withId = /*#__PURE__*/_withScopeId(\\"test\\")
65
76
_pushScopeId(\\"test\\")
87
const _hoisted_1 = /*#__PURE__*/_createElementVNode(\\"div\\", null, \\"hello\\", -1 /* HOISTED */)
98
const _hoisted_2 = /*#__PURE__*/_createElementVNode(\\"div\\", null, \\"world\\", -1 /* HOISTED */)
109
_popScopeId()
1110
12-
export const render = /*#__PURE__*/_withId((_ctx, _cache) => {
11+
export function render(_ctx, _cache) {
1312
return (_openBlock(), _createElementBlock(\\"div\\", null, [
1413
_hoisted_1,
1514
_createTextVNode(_toDisplayString(_ctx.foo), 1 /* TEXT */),
@@ -20,9 +19,8 @@ export const render = /*#__PURE__*/_withId((_ctx, _cache) => {
2019

2120
exports[`scopeId compiler support should wrap default slot 1`] = `
2221
"import { createElementVNode as _createElementVNode, resolveComponent as _resolveComponent, withCtx as _withCtx, openBlock as _openBlock, createBlock as _createBlock, withScopeId as _withScopeId } from \\"vue\\"
23-
const _withId = /*#__PURE__*/_withScopeId(\\"test\\")
2422
25-
export const render = /*#__PURE__*/_withId((_ctx, _cache) => {
23+
export function render(_ctx, _cache) {
2624
const _component_Child = _resolveComponent(\\"Child\\")
2725
2826
return (_openBlock(), _createBlock(_component_Child, null, {
@@ -36,9 +34,8 @@ export const render = /*#__PURE__*/_withId((_ctx, _cache) => {
3634

3735
exports[`scopeId compiler support should wrap dynamic slots 1`] = `
3836
"import { createElementVNode as _createElementVNode, resolveComponent as _resolveComponent, withCtx as _withCtx, renderList as _renderList, createSlots as _createSlots, openBlock as _openBlock, createBlock as _createBlock, withScopeId as _withScopeId } from \\"vue\\"
39-
const _withId = /*#__PURE__*/_withScopeId(\\"test\\")
4037
41-
export const render = /*#__PURE__*/_withId((_ctx, _cache) => {
38+
export function render(_ctx, _cache) {
4239
const _component_Child = _resolveComponent(\\"Child\\")
4340
4441
return (_openBlock(), _createBlock(_component_Child, null, _createSlots({ _: 2 /* DYNAMIC */ }, [
@@ -64,9 +61,8 @@ export const render = /*#__PURE__*/_withId((_ctx, _cache) => {
6461

6562
exports[`scopeId compiler support should wrap named slots 1`] = `
6663
"import { toDisplayString as _toDisplayString, createTextVNode as _createTextVNode, createElementVNode as _createElementVNode, resolveComponent as _resolveComponent, withCtx as _withCtx, openBlock as _openBlock, createBlock as _createBlock, withScopeId as _withScopeId } from \\"vue\\"
67-
const _withId = /*#__PURE__*/_withScopeId(\\"test\\")
6864
69-
export const render = /*#__PURE__*/_withId((_ctx, _cache) => {
65+
export function render(_ctx, _cache) {
7066
const _component_Child = _resolveComponent(\\"Child\\")
7167
7268
return (_openBlock(), _createBlock(_component_Child, null, {

packages/compiler-core/src/codegen.ts

+2-28
Original file line numberDiff line numberDiff line change
@@ -234,14 +234,7 @@ export function generate(
234234
? args.map(arg => `${arg}: any`).join(',')
235235
: args.join(', ')
236236

237-
if (genScopeId && !isSetupInlined) {
238-
// root-level _withId wrapping is no longer necessary after 3.0.8 and is
239-
// a noop, it's only kept so that code compiled with 3.0.8+ can run with
240-
// runtime < 3.0.8.
241-
// TODO: consider removing in 3.1
242-
push(`const ${functionName} = ${PURE_ANNOTATION}${WITH_ID}(`)
243-
}
244-
if (isSetupInlined || genScopeId) {
237+
if (isSetupInlined) {
245238
push(`(${signature}) => {`)
246239
} else {
247240
push(`function ${functionName}(${signature}) {`)
@@ -390,14 +383,7 @@ function genModulePreamble(
390383
genScopeId: boolean,
391384
inline?: boolean
392385
) {
393-
const {
394-
push,
395-
newline,
396-
optimizeImports,
397-
runtimeModuleName,
398-
scopeId,
399-
helper
400-
} = context
386+
const { push, newline, optimizeImports, runtimeModuleName } = context
401387

402388
if (genScopeId) {
403389
ast.helpers.push(WITH_SCOPE_ID)
@@ -446,18 +432,6 @@ function genModulePreamble(
446432
newline()
447433
}
448434

449-
// we technically don't need this anymore since `withCtx` already sets the
450-
// correct scopeId, but this is necessary for backwards compat
451-
// TODO: consider removing in 3.1
452-
if (genScopeId) {
453-
push(
454-
`const ${WITH_ID} = ${PURE_ANNOTATION}${helper(
455-
WITH_SCOPE_ID
456-
)}("${scopeId}")`
457-
)
458-
newline()
459-
}
460-
461435
genHoists(ast.hoists, context)
462436
newline()
463437

packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap

-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,6 @@ return (_ctx, _cache) => {
326326
327327
exports[`SFC compile <script setup> inlineTemplate mode should not wrap render fn with withId when having scoped styles 1`] = `
328328
"import { toDisplayString as _toDisplayString, openBlock as _openBlock, createElementBlock as _createElementBlock, withScopeId as _withScopeId } from \\"vue\\"
329-
const _withId = /*#__PURE__*/_withScopeId(\\"data-v-xxxxxxxx\\")
330329
331330
332331
export default {

packages/compiler-sfc/__tests__/compileScript.spec.ts

-26
Original file line numberDiff line numberDiff line change
@@ -476,32 +476,6 @@ defineExpose({ foo: 123 })
476476
expect(content).toMatch(`ssrInterpolate`)
477477
assertCode(content)
478478
})
479-
480-
// _withId is only generated for backwards compat and is a noop when called
481-
// in module scope.
482-
// when inside setup(), currentInstance will be non-null and _withId will
483-
// no longer be noop and cause scopeId errors.
484-
// TODO: this test should no longer be necessary if we remove _withId
485-
// codegen in 3.1
486-
test('should not wrap render fn with withId when having scoped styles', async () => {
487-
const { content } = compile(
488-
`
489-
<script setup>
490-
const msg = 1
491-
</script>
492-
<template><h1>{{ msg }}</h1></template>
493-
<style scoped>
494-
h1 { color: red; }
495-
</style>
496-
`,
497-
{
498-
inlineTemplate: true
499-
}
500-
)
501-
expect(content).toMatch(`return (_ctx, _cache`)
502-
expect(content).not.toMatch(`_withId(`)
503-
assertCode(content)
504-
})
505479
})
506480

507481
describe('with TypeScript', () => {

packages/compiler-sfc/src/compileScript.ts

-9
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,6 @@ export function compileScript(
148148
)
149149
}
150150

151-
// TODO remove on 3.2
152-
if (sfc.template && sfc.template.attrs['inherit-attrs'] === 'false') {
153-
warnOnce(
154-
`Experimental support for <template inherit-attrs="false"> support has ` +
155-
`been removed. Use a <script> block with \`export default\` to ` +
156-
`declare options.`
157-
)
158-
}
159-
160151
const scopeId = options.id ? options.id.replace(/^data-v-/, '') : ''
161152
const cssVars = sfc.cssVars
162153
const scriptLang = script && script.lang

packages/compiler-ssr/__tests__/ssrScopeId.spec.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ describe('ssr: scopeId', () => {
1212
).toMatchInlineSnapshot(`
1313
"import { withScopeId as _withScopeId } from \\"vue\\"
1414
import { ssrRenderAttrs as _ssrRenderAttrs } from \\"@vue/server-renderer\\"
15-
const _withId = /*#__PURE__*/_withScopeId(\\"data-v-xxxxxxx\\")
1615
17-
export const ssrRender = /*#__PURE__*/_withId((_ctx, _push, _parent, _attrs) => {
16+
export function ssrRender(_ctx, _push, _parent, _attrs) {
1817
_push(\`<div\${_ssrRenderAttrs(_attrs)} data-v-xxxxxxx><span data-v-xxxxxxx>hello</span></div>\`)
1918
})"
2019
`)
@@ -30,9 +29,8 @@ describe('ssr: scopeId', () => {
3029
).toMatchInlineSnapshot(`
3130
"import { resolveComponent as _resolveComponent, withCtx as _withCtx, createTextVNode as _createTextVNode, withScopeId as _withScopeId } from \\"vue\\"
3231
import { ssrRenderComponent as _ssrRenderComponent } from \\"@vue/server-renderer\\"
33-
const _withId = /*#__PURE__*/_withScopeId(\\"data-v-xxxxxxx\\")
3432
35-
export const ssrRender = /*#__PURE__*/_withId((_ctx, _push, _parent, _attrs) => {
33+
export function ssrRender(_ctx, _push, _parent, _attrs) {
3634
const _component_foo = _resolveComponent(\\"foo\\")
3735
3836
_push(_ssrRenderComponent(_component_foo, _attrs, {
@@ -60,9 +58,8 @@ describe('ssr: scopeId', () => {
6058
).toMatchInlineSnapshot(`
6159
"import { resolveComponent as _resolveComponent, withCtx as _withCtx, createVNode as _createVNode, withScopeId as _withScopeId } from \\"vue\\"
6260
import { ssrRenderComponent as _ssrRenderComponent } from \\"@vue/server-renderer\\"
63-
const _withId = /*#__PURE__*/_withScopeId(\\"data-v-xxxxxxx\\")
6461
65-
export const ssrRender = /*#__PURE__*/_withId((_ctx, _push, _parent, _attrs) => {
62+
export function ssrRender(_ctx, _push, _parent, _attrs) {
6663
const _component_foo = _resolveComponent(\\"foo\\")
6764
6865
_push(_ssrRenderComponent(_component_foo, _attrs, {
@@ -90,9 +87,8 @@ describe('ssr: scopeId', () => {
9087
).toMatchInlineSnapshot(`
9188
"import { resolveComponent as _resolveComponent, withCtx as _withCtx, createVNode as _createVNode, withScopeId as _withScopeId } from \\"vue\\"
9289
import { ssrRenderComponent as _ssrRenderComponent } from \\"@vue/server-renderer\\"
93-
const _withId = /*#__PURE__*/_withScopeId(\\"data-v-xxxxxxx\\")
9490
95-
export const ssrRender = /*#__PURE__*/_withId((_ctx, _push, _parent, _attrs) => {
91+
export function ssrRender(_ctx, _push, _parent, _attrs) {
9692
const _component_foo = _resolveComponent(\\"foo\\")
9793
const _component_bar = _resolveComponent(\\"bar\\")
9894

packages/runtime-core/src/compat/compatConfig.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -552,8 +552,8 @@ export function validateCompatConfig(
552552
warn(
553553
`Deprecation config "${key}" is compiler-specific and you are ` +
554554
`running a runtime-only build of Vue. This deprecation should be ` +
555-
`configured via compiler options in your build setup instead.`
556-
// TODO link to migration build docs on build setup
555+
`configured via compiler options in your build setup instead.\n` +
556+
`Details: https://v3.vuejs.org/guide/migration/migration-build.html`
557557
)
558558
}
559559
} else {

0 commit comments

Comments
 (0)