提交 c54d85e1 编写于 作者: fxy060608's avatar fxy060608

fix(mp): ensure scoped slots context

上级 69de2d3d
...@@ -5055,8 +5055,8 @@ function findScopedSlotInvoker(vueId, instance) { ...@@ -5055,8 +5055,8 @@ function findScopedSlotInvoker(vueId, instance) {
//@ts-ignore //@ts-ignore
function withScopedSlot(fn, { name, path, vueId, }) { function withScopedSlot(fn, { name, path, vueId, }) {
fn.path = path;
const instance = getCurrentInstance(); const instance = getCurrentInstance();
fn.path = path;
const scopedSlots = (instance.$ssi || const scopedSlots = (instance.$ssi ||
(instance.$ssi = {})); (instance.$ssi = {}));
const invoker = scopedSlots[vueId] || const invoker = scopedSlots[vueId] ||
...@@ -5081,7 +5081,10 @@ function createScopedSlotInvoker(instance) { ...@@ -5081,7 +5081,10 @@ function createScopedSlotInvoker(instance) {
// 循环第一个 slot 时,重置 data // 循环第一个 slot 时,重置 data
slot.data = {}; slot.data = {};
} }
// 确保当前 slot 的上下文,类似 withCtx
const prevInstance = setCurrentRenderingInstance(instance);
slot.data[key] = slot.fn(args, key, slotName + (hasKey ? '-' + key : '')); slot.data[key] = slot.fn(args, key, slotName + (hasKey ? '-' + key : ''));
setCurrentRenderingInstance(prevInstance);
// TODO 简单的 forceUpdate,理论上,可以仅对 scoped slot 部分数据 diff 更新 // TODO 简单的 forceUpdate,理论上,可以仅对 scoped slot 部分数据 diff 更新
instance.proxy.$forceUpdate(); instance.proxy.$forceUpdate();
}; };
...@@ -5130,4 +5133,4 @@ function createApp(rootComponent, rootProps = null) { ...@@ -5130,4 +5133,4 @@ function createApp(rootComponent, rootProps = null) {
} }
const createSSRApp = createApp; const createSSRApp = createApp;
export { EffectScope, Fragment, ReactiveEffect, Text, c, callWithAsyncErrorHandling, callWithErrorHandling, computed, createApp, createSSRApp, createVNode$1 as createVNode, createVueApp, customRef, d, defineComponent, defineEmits, defineExpose, defineProps, e, effect, effectScope, f, getCurrentInstance, getCurrentScope, h, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, logError, markRaw, mergeDefaults, mergeProps, n, nextTick, o, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onScopeDispose, onUnmounted, onUpdated, patch, provide, proxyRefs, queuePostFlushCb, r, reactive, readonly, ref, resolveComponent, resolveDirective, resolveFilter, s, setupDevtoolsPlugin, shallowReactive, shallowReadonly, shallowRef, stop, t, toHandlers, toRaw, toRef, toRefs, triggerRef, unref, useAttrs, useSSRContext, useSlots, version, w, warn$1 as warn, watch, watchEffect, watchPostEffect, watchSyncEffect, withAsyncContext, withCtx, withDefaults, withDirectives, withModifiers, withScopeId }; export { EffectScope, Fragment, ReactiveEffect, Text, c, callWithAsyncErrorHandling, callWithErrorHandling, computed, createApp, createSSRApp, createVNode$1 as createVNode, createVueApp, customRef, d, defineComponent, defineEmits, defineExpose, defineProps, e, effect, effectScope, f, getCurrentInstance, getCurrentScope, h, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, logError, markRaw, mergeDefaults, mergeProps, n, nextTick, o, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onScopeDispose, onUnmounted, onUpdated, patch, provide, proxyRefs, queuePostFlushCb, r, reactive, readonly, ref, resolveComponent, resolveDirective, resolveFilter, s, setCurrentRenderingInstance, setupDevtoolsPlugin, shallowReactive, shallowReadonly, shallowRef, stop, t, toHandlers, toRaw, toRef, toRefs, triggerRef, unref, useAttrs, useSSRContext, useSlots, version, w, warn$1 as warn, watch, watchEffect, watchPostEffect, watchSyncEffect, withAsyncContext, withCtx, withDefaults, withDirectives, withModifiers, withScopeId };
...@@ -4729,4 +4729,4 @@ function createVueApp(rootComponent, rootProps = null) { ...@@ -4729,4 +4729,4 @@ function createVueApp(rootComponent, rootProps = null) {
function withModifiers() { } function withModifiers() { }
function createVNode$1() { } function createVNode$1() { }
export { EffectScope, Fragment, ReactiveEffect, Text, callWithAsyncErrorHandling, callWithErrorHandling, computed, createVNode$1 as createVNode, createVueApp, customRef, defineComponent, defineEmits, defineExpose, defineProps, effect, effectScope, getCurrentInstance, getCurrentScope, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, logError, markRaw, mergeDefaults, mergeProps, nextTick, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onScopeDispose, onUnmounted, onUpdated, patch, provide, proxyRefs, queuePostFlushCb, reactive, readonly, ref, resolveComponent, resolveDirective, resolveFilter, shallowReactive, shallowReadonly, shallowRef, stop, toHandlers, toRaw, toRef, toRefs, triggerRef, unref, useAttrs, useSSRContext, useSlots, version, warn$1 as warn, watch, watchEffect, watchPostEffect, watchSyncEffect, withAsyncContext, withCtx, withDefaults, withDirectives, withModifiers, withScopeId }; export { EffectScope, Fragment, ReactiveEffect, Text, callWithAsyncErrorHandling, callWithErrorHandling, computed, createVNode$1 as createVNode, createVueApp, customRef, defineComponent, defineEmits, defineExpose, defineProps, effect, effectScope, getCurrentInstance, getCurrentScope, inject, injectHook, isInSSRComponentSetup, isProxy, isReactive, isReadonly, isRef, logError, markRaw, mergeDefaults, mergeProps, nextTick, onActivated, onBeforeMount, onBeforeUnmount, onBeforeUpdate, onDeactivated, onErrorCaptured, onMounted, onRenderTracked, onRenderTriggered, onScopeDispose, onUnmounted, onUpdated, patch, provide, proxyRefs, queuePostFlushCb, reactive, readonly, ref, resolveComponent, resolveDirective, resolveFilter, setCurrentRenderingInstance, shallowReactive, shallowReadonly, shallowRef, stop, toHandlers, toRaw, toRef, toRefs, triggerRef, unref, useAttrs, useSSRContext, useSlots, version, warn$1 as warn, watch, watchEffect, watchPostEffect, watchSyncEffect, withAsyncContext, withCtx, withDefaults, withDirectives, withModifiers, withScopeId };
import type { ComponentInternalInstance } from 'vue' import type { ComponentInternalInstance } from 'vue'
//@ts-ignore //@ts-ignore
import { patch, getCurrentInstance } from 'vue' import { patch, getCurrentInstance, setCurrentRenderingInstance } from 'vue'
export interface ScopedSlotInvokers { export interface ScopedSlotInvokers {
[vueId: string]: ScopedSlotInvoker [vueId: string]: ScopedSlotInvoker
...@@ -36,8 +36,8 @@ export function withScopedSlot( ...@@ -36,8 +36,8 @@ export function withScopedSlot(
vueId: string vueId: string
} }
) { ) {
fn.path = path
const instance = getCurrentInstance() as ComponentInternalInstance const instance = getCurrentInstance() as ComponentInternalInstance
fn.path = path
const scopedSlots = ((instance as any).$ssi || const scopedSlots = ((instance as any).$ssi ||
(((instance as any).$ssi as ScopedSlotInvokers) = {})) as ScopedSlotInvokers (((instance as any).$ssi as ScopedSlotInvokers) = {})) as ScopedSlotInvokers
const invoker = const invoker =
...@@ -67,7 +67,10 @@ function createScopedSlotInvoker(instance: ComponentInternalInstance) { ...@@ -67,7 +67,10 @@ function createScopedSlotInvoker(instance: ComponentInternalInstance) {
// 循环第一个 slot 时,重置 data // 循环第一个 slot 时,重置 data
slot.data = {} slot.data = {}
} }
// 确保当前 slot 的上下文,类似 withCtx
const prevInstance = setCurrentRenderingInstance(instance)
slot.data[key] = slot.fn(args, key, slotName + (hasKey ? '-' + key : '')) slot.data[key] = slot.fn(args, key, slotName + (hasKey ? '-' + key : ''))
setCurrentRenderingInstance(prevInstance)
// TODO 简单的 forceUpdate,理论上,可以仅对 scoped slot 部分数据 diff 更新 // TODO 简单的 forceUpdate,理论上,可以仅对 scoped slot 部分数据 diff 更新
instance.proxy!.$forceUpdate() instance.proxy!.$forceUpdate()
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册