Skip to content

Commit 099f3ba

Browse files
committed
perf: skip scoped slots normalization when possible
1 parent 7a0dfd0 commit 099f3ba

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/core/instance/render.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ export function renderMixin (Vue: Class<Component>) {
7373
if (_parentVnode) {
7474
vm.$scopedSlots = normalizeScopedSlots(
7575
_parentVnode.data.scopedSlots,
76-
vm.$slots
76+
vm.$slots,
77+
vm.$scopedSlots
7778
)
7879
}
7980

src/core/vdom/helpers/normalize-scoped-slots.js

+11-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@
22

33
import { def } from 'core/util/lang'
44
import { normalizeChildren } from 'core/vdom/helpers/normalize-children'
5+
import { emptyObject } from 'shared/util'
56

67
export function normalizeScopedSlots (
78
slots: { [key: string]: Function } | void,
8-
normalSlots: { [key: string]: Array<VNode> }
9+
normalSlots: { [key: string]: Array<VNode> },
10+
prevSlots?: { [key: string]: Function } | void
911
): any {
1012
let res
1113
if (!slots) {
1214
res = {}
1315
} else if (slots._normalized) {
14-
return slots
16+
// fast path 1: child component re-render only, parent did not change
17+
return slots._normalized
18+
} else if (slots.$stable && prevSlots && prevSlots !== emptyObject) {
19+
// fast path 2: stable scoped slots, only need to normalize once
20+
return prevSlots
1521
} else {
1622
res = {}
1723
for (const key in slots) {
@@ -26,7 +32,9 @@ export function normalizeScopedSlots (
2632
res[key] = proxyNormalSlot(normalSlots, key)
2733
}
2834
}
29-
def(res, '_normalized', true)
35+
if (slots) {
36+
(slots: any)._normalized = res
37+
}
3038
def(res, '$stable', slots ? !!slots.$stable : true)
3139
return res
3240
}

0 commit comments

Comments
 (0)