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: 插槽组件局部更新使得事件id增长,极端情况下可能导致页面卡死 #5033

Open
wants to merge 3 commits into
base: next
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions packages/shims-vue-runtime.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ declare module '@vue/runtime-core' {
// mp
$updateScopedSlots: () => void
$scopedSlotsData?: { path: string; index: number; data: Data }[]
$currentSlotComponentInstance?: ComponentInternalInstance
// h5 | app
$wxsModules?: string[]
// 暂定 h5
Expand Down
16 changes: 15 additions & 1 deletion packages/uni-mp-vue/dist/vue.runtime.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -7781,7 +7781,19 @@ function vOn(value, key) {
(isString(key) || typeof key === 'number')
? '_' + key
: '';
const name = 'e' + instance.$ei++ + extraKey;
let name;
if (instance.$currentSlotComponentInstance) {
const slotComponentInstance = instance.$currentSlotComponentInstance;
name =
'e' +
slotComponentInstance.uid +
'_' +
slotComponentInstance.$ei++ +
extraKey;
}
else {
name = 'e' + instance.$ei++ + extraKey;
}
const mpInstance = ctx.$scope;
if (!value) {
// remove
Expand Down Expand Up @@ -7982,7 +7994,9 @@ function createScopedSlotInvoker(instance) {
index = index || 0;
// 确保当前 slot 的上下文,类似 withCtx
const prevInstance = setCurrentRenderingInstance(instance);
instance.$currentSlotComponentInstance = prevInstance;
const data = slot.fn(args, slotName + (hasIndex ? '-' + index : ''), index);
delete instance.$currentSlotComponentInstance;
const path = slot.fn.path;
setCurrentRenderingInstance(prevInstance);
(instance.$scopedSlotsData || (instance.$scopedSlotsData = [])).push({
Expand Down
15 changes: 14 additions & 1 deletion packages/uni-mp-vue/src/helpers/vOn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface Invoker {
export function vOn(value: EventValue | undefined, key?: number | string) {
const instance = getCurrentInstance()! as unknown as {
$ei: number
$currentSlotComponentInstance?: { uid: number; $ei: number }
ctx: { $scope: Record<string, any>; $mpPlatform: UniApp.PLATFORM }
}
const ctx = instance.ctx
Expand All @@ -36,7 +37,19 @@ export function vOn(value: EventValue | undefined, key?: number | string) {
? '_' + key
: ''

const name = 'e' + instance.$ei++ + extraKey
let name: string

if (instance.$currentSlotComponentInstance) {
const slotComponentInstance = instance.$currentSlotComponentInstance
name =
'e' +
slotComponentInstance.uid +
'_' +
slotComponentInstance.$ei++ +
extraKey
} else {
name = 'e' + instance.$ei++ + extraKey
}

const mpInstance = ctx.$scope
if (!value) {
Expand Down
2 changes: 2 additions & 0 deletions packages/uni-mp-vue/src/helpers/withScopedSlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ function createScopedSlotInvoker(instance: ComponentInternalInstance) {
index = index || 0
// 确保当前 slot 的上下文,类似 withCtx
const prevInstance = setCurrentRenderingInstance(instance)
instance.$currentSlotComponentInstance = prevInstance
const data = slot.fn(args, slotName + (hasIndex ? '-' + index : ''), index)
delete instance.$currentSlotComponentInstance
const path = slot.fn.path
setCurrentRenderingInstance(prevInstance)
;(instance.$scopedSlotsData || (instance.$scopedSlotsData = [])).push({
Expand Down