Skip to content

Commit

Permalink
chore(core/component/render/wrappers): move vue internals to the engine
Browse files Browse the repository at this point in the history
  • Loading branch information
shining-mind committed Jan 24, 2024
1 parent 22b034b commit 82188f3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
19 changes: 18 additions & 1 deletion src/core/component/engines/vue3/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,25 @@ export const

export const
mergeProps = wrapMergeProps(superMergeProps),
renderList = wrapRenderList(superRenderList, superWithCtx),
renderSlot = wrapRenderSlot(superRenderSlot);

export const renderList = wrapRenderList(
superRenderList,
(...args: Parameters<typeof superWithCtx>) => {
// Vue has two contexts for instances: `currentInstance` and `currentRenderingInstance`.
// The context for the renderList should be a `currentRenderingInstance` because `renderList` is called during component rendering.

Check failure on line 132 in src/core/component/engines/vue3/render.ts

View workflow job for this annotation

GitHub Actions / linters (20.x)

This line has a length of 135. Maximum allowed is 120

Check failure on line 132 in src/core/component/engines/vue3/render.ts

View workflow job for this annotation

GitHub Actions / linters (20.x)

This line has a length of 135. Maximum allowed is 120
const fn = superWithCtx(...args);

// Enable block tracking
// @see https://github.com/vuejs/core/blob/45984d559fe0c036657d5f2626087ea8eec205a8/packages/runtime-core/src/componentRenderContext.ts#L88
if ('_d' in fn) {
(<Function & {_d: boolean}>fn)._d = false;
}

return fn;
}
);

export const
withCtx = wrapWithCtx(superWithCtx),
withDirectives = wrapWithDirectives(superWithDirectives),
Expand Down
14 changes: 3 additions & 11 deletions src/core/component/render/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,9 @@ export function wrapMergeProps<T extends typeof mergeProps>(original: T): T {

/**
* Wrapper for the component library `renderList` function
*
* @param original
* @param withCtx
*/
export function wrapRenderList<T extends typeof renderList, C extends typeof withCtx>(original: T, withCtx: C): T {
return Object.cast(function renderList(
Expand All @@ -270,20 +272,10 @@ export function wrapRenderList<T extends typeof renderList, C extends typeof wit
cb: AnyFunction
) {
const
// `v-for` is executed during rendering,
// so `r.getCurrentInstance` should return `currentRenderingInstance`
ctx = this.$renderEngine.r.getCurrentInstance(),
// Preserve ctx for callback. It will guarantee
// that during async render there will be correct `currentRenderingInstance`
// which affects components' refs
// Preserve rendering context for the async render
wrappedCb: AnyFunction = Object.cast(withCtx(cb, ctx));

// Enable block tracking
// @see https://github.com/vuejs/core/blob/45984d559fe0c036657d5f2626087ea8eec205a8/packages/runtime-core/src/componentRenderContext.ts#L88
if ('_d' in wrappedCb) {
(<AnyFunction & {_d: boolean}>wrappedCb)._d = false;
}

this.$emit('[[V_FOR_CB]]', wrappedCb);
return original(src, wrappedCb);
});
Expand Down

0 comments on commit 82188f3

Please sign in to comment.