From 4ecc21c29ec12bb33d3b426cb4d42c579e9b0f2d Mon Sep 17 00:00:00 2001 From: Rahul Kadyan Date: Sat, 1 Dec 2018 04:01:44 +0530 Subject: [PATCH] feat(devtools): store functional render context on vnode in development (#8586) --- src/core/vdom/create-functional-component.js | 9 ++++++--- src/core/vdom/vnode.js | 1 + 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/core/vdom/create-functional-component.js b/src/core/vdom/create-functional-component.js index efed801db7d..4233ade22e8 100644 --- a/src/core/vdom/create-functional-component.js +++ b/src/core/vdom/create-functional-component.js @@ -105,24 +105,27 @@ export function createFunctionalComponent ( const vnode = options.render.call(null, renderContext._c, renderContext) if (vnode instanceof VNode) { - return cloneAndMarkFunctionalResult(vnode, data, renderContext.parent, options) + return cloneAndMarkFunctionalResult(vnode, data, renderContext.parent, options, renderContext) } else if (Array.isArray(vnode)) { const vnodes = normalizeChildren(vnode) || [] const res = new Array(vnodes.length) for (let i = 0; i < vnodes.length; i++) { - res[i] = cloneAndMarkFunctionalResult(vnodes[i], data, renderContext.parent, options) + res[i] = cloneAndMarkFunctionalResult(vnodes[i], data, renderContext.parent, options, renderContext) } return res } } -function cloneAndMarkFunctionalResult (vnode, data, contextVm, options) { +function cloneAndMarkFunctionalResult (vnode, data, contextVm, options, renderContext) { // #7817 clone node before setting fnContext, otherwise if the node is reused // (e.g. it was from a cached normal slot) the fnContext causes named slots // that should not be matched to match. const clone = cloneVNode(vnode) clone.fnContext = contextVm clone.fnOptions = options + if (process.env.NODE_ENV !== 'production') { + ;(clone.devtoolsMeta = clone.devtoolsMeta || {}).renderContext = renderContext + } if (data.slot) { (clone.data || (clone.data = {})).slot = data.slot } diff --git a/src/core/vdom/vnode.js b/src/core/vdom/vnode.js index c3e00078fea..0e3e2e9e635 100644 --- a/src/core/vdom/vnode.js +++ b/src/core/vdom/vnode.js @@ -26,6 +26,7 @@ export default class VNode { ssrContext: Object | void; fnContext: Component | void; // real context vm for functional nodes fnOptions: ?ComponentOptions; // for SSR caching + devtoolsMeta: ?Object; // used to store functional render context for devtools fnScopeId: ?string; // functional scope id support constructor (