Skip to content

Commit 0ddf04a

Browse files
committed
fix: compatibility with 2.6 scoped slots optimizations
1 parent 9e6a394 commit 0ddf04a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/index.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,16 @@ exports.rerender = tryWrap((id, options) => {
167167
if (Array.isArray(instance.$options.cached)) {
168168
instance.$options.cached = []
169169
}
170+
170171
// post 2.5.4: v-once trees are cached on instance._staticTrees.
171172
// Pure static trees are cached on the staticRenderFns array
172173
// (both already reset above)
174+
175+
// 2.6: temporarily mark rendered scoped slots as unstable so that
176+
// child components can be forced to update
177+
const restore = patchScopedSlots(instance)
173178
instance.$forceUpdate()
179+
instance.$nextTick(restore)
174180
})
175181
} else {
176182
// functional or no instance created yet
@@ -241,3 +247,17 @@ exports.reload = tryWrap((id, options) => {
241247
}
242248
})
243249
})
250+
251+
// 2.6 optimizes template-compiled scoped slots and skips updates if child
252+
// only uses scoped slots. We need to patch the scoped slots resolving helper
253+
// to temporarily mark all scoped slots as unstable in order to force child
254+
// updates.
255+
function patchScopedSlots (instance) {
256+
if (!instance._u) return
257+
// https://github.com/vuejs/vue/blob/dev/src/core/instance/render-helpers/resolve-scoped-slots.js
258+
const original = instance._u
259+
instance._u = slots => original(slots, true)
260+
return () => {
261+
instance._u = original
262+
}
263+
}

0 commit comments

Comments
 (0)