Skip to content

Commit

Permalink
fix: compatibility with 2.6 scoped slots optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Feb 11, 2019
1 parent 43b3e8d commit 9706a2e
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,16 @@ exports.rerender = tryWrap((id, options) => {
if (Array.isArray(instance.$options.cached)) {
instance.$options.cached = []
}

// post 2.5.4: v-once trees are cached on instance._staticTrees.
// Pure static trees are cached on the staticRenderFns array
// (both already reset above)

// 2.6: temporarily mark rendered scoped slots as unstable so that
// child components can be forced to update
const restore = patchScopedSlots(instance)
instance.$forceUpdate()
instance.$nextTick(restore)
})
} else {
// functional or no instance created yet
Expand Down Expand Up @@ -241,3 +247,17 @@ exports.reload = tryWrap((id, options) => {
}
})
})

// 2.6 optimizes template-compiled scoped slots and skips updates if child
// only uses scoped slots. We need to patch the scoped slots resolving helper
// to temporarily mark all scoped slots as unstable in order to force child
// updates.
function patchScopedSlots (instance) {
if (!instance._u) return
// https://github.com/vuejs/vue/blob/dev/src/core/instance/render-helpers/resolve-scoped-slots.js
const original = instance._u
instance._u = slots => original(slots, true)
return () => {
instance._u = original
}
}

0 comments on commit 9706a2e

Please sign in to comment.