Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(compiler-core): the component always uses the NEED_PATCH flag to avoid patch errors #2061

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const render = /*#__PURE__*/_withId(function render(_ctx, _cache) {
_createVNode(\\"div\\")
]),
_: 1
}))
}, 512 /* NEED_PATCH */))
})"
`;

Expand Down Expand Up @@ -77,7 +77,7 @@ export const render = /*#__PURE__*/_withId(function render(_ctx, _cache) {
_createVNode(\\"div\\")
]),
_: 1
}))
}, 512 /* NEED_PATCH */))
})"
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ return function render(_ctx, _cache) {

return (_openBlock(), _createBlock(\\"div\\", null, [
_createVNode(\\"div\\", _hoisted_1, [
_createVNode(_component_Comp)
_createVNode(_component_Comp, null, null, 512 /* NEED_PATCH */)
])
]))
}
Expand Down Expand Up @@ -248,7 +248,7 @@ return function render(_ctx, _cache) {
_createTextVNode(_toDisplayString(_ctx.foo), 1 /* TEXT */)
]),
_: 1
}))
}, 512 /* NEED_PATCH */))
}
}"
`;
Expand Down Expand Up @@ -297,7 +297,7 @@ return function render(_ctx, _cache) {
const _component_Comp = _resolveComponent(\\"Comp\\")

return (_openBlock(), _createBlock(\\"div\\", null, [
_createVNode(_component_Comp)
_createVNode(_component_Comp, null, null, 512 /* NEED_PATCH */)
]))
}
}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ return function render(_ctx, _cache) {
_createVNode(\\"div\\")
]),
_: 1
}))
}, 512 /* NEED_PATCH */))
}"
`;

Expand Down Expand Up @@ -129,7 +129,7 @@ return function render(_ctx, _cache) {
_createVNode(\\"span\\")
]),
_: 1
}))
}, 512 /* NEED_PATCH */))
}
}"
`;
Expand All @@ -153,7 +153,7 @@ return function render(_ctx, _cache) {
_toDisplayString(_ctx.baz)
]),
_: 1
}))
}, 512 /* NEED_PATCH */))
}"
`;

Expand All @@ -179,7 +179,7 @@ return function render(_ctx, _cache) {
return (_openBlock(), _createBlock(_component_Comp, null, {
named: _withCtx(({ foo }) => [_toDisplayString(foo), _toDisplayString(_ctx.bar)]),
_: 1
}))
}, 512 /* NEED_PATCH */))
}"
`;

Expand All @@ -192,7 +192,7 @@ return function render(_ctx, _cache) {
return (_openBlock(), _createBlock(_component_Comp, null, {
default: _withCtx(({ foo }) => [_toDisplayString(foo), _toDisplayString(_ctx.bar)]),
_: 1
}))
}, 512 /* NEED_PATCH */))
}"
`;

Expand All @@ -206,6 +206,6 @@ return function render(_ctx, _cache) {
one: _withCtx(({ foo }) => [_toDisplayString(foo), _toDisplayString(_ctx.bar)]),
two: _withCtx(({ bar }) => [_toDisplayString(_ctx.foo), _toDisplayString(bar)]),
_: 1
}))
}, 512 /* NEED_PATCH */))
}"
`;
2 changes: 1 addition & 1 deletion packages/compiler-core/__tests__/transforms/vSlot.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ describe('compiler: transform component slots', () => {
if (shouldForce) {
expect(flag).toBe(genFlagText(PatchFlags.DYNAMIC_SLOTS))
} else {
expect(flag).toBeUndefined()
expect(flag).toBe(genFlagText(PatchFlags.NEED_PATCH))
}
}

Expand Down
12 changes: 12 additions & 0 deletions packages/compiler-core/src/transforms/transformElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
isSymbol,
isOn,
isObject,
isString,
isReservedProp
} from '@vue/shared'
import { createCompilerError, ErrorCodes } from '../errors'
Expand Down Expand Up @@ -176,6 +177,17 @@ export const transformElement: NodeTransform = (node, context) => {
}
}

// #2058
// when the component is not registered, it will resolve to plain element,
// we add the `NEED_PATCH` flag here to avoid accidental failure of tracking.
if (
isString(vnodeTag) &&
/^_component_/.test(vnodeTag) &&
patchFlag === 0
) {
patchFlag |= PatchFlags.NEED_PATCH
}

// patchFlag & dynamicPropNames
if (patchFlag !== 0) {
if (__DEV__) {
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-ssr/__tests__/ssrScopeId.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ describe('ssr: scopeId', () => {
_createVNode(\\"span\\")
]),
_: 1
})
}, 512 /* NEED_PATCH */)
]
}
}),
Expand Down