Skip to content

Commit ab7ea79

Browse files
znckaJean
authored andcommitted
feat(devtools): store functional render context on vnode in development (vuejs#8586)
1 parent f42e127 commit ab7ea79

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/core/vdom/create-functional-component.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -105,24 +105,27 @@ export function createFunctionalComponent (
105105
const vnode = options.render.call(null, renderContext._c, renderContext)
106106

107107
if (vnode instanceof VNode) {
108-
return cloneAndMarkFunctionalResult(vnode, data, renderContext.parent, options)
108+
return cloneAndMarkFunctionalResult(vnode, data, renderContext.parent, options, renderContext)
109109
} else if (Array.isArray(vnode)) {
110110
const vnodes = normalizeChildren(vnode) || []
111111
const res = new Array(vnodes.length)
112112
for (let i = 0; i < vnodes.length; i++) {
113-
res[i] = cloneAndMarkFunctionalResult(vnodes[i], data, renderContext.parent, options)
113+
res[i] = cloneAndMarkFunctionalResult(vnodes[i], data, renderContext.parent, options, renderContext)
114114
}
115115
return res
116116
}
117117
}
118118

119-
function cloneAndMarkFunctionalResult (vnode, data, contextVm, options) {
119+
function cloneAndMarkFunctionalResult (vnode, data, contextVm, options, renderContext) {
120120
// #7817 clone node before setting fnContext, otherwise if the node is reused
121121
// (e.g. it was from a cached normal slot) the fnContext causes named slots
122122
// that should not be matched to match.
123123
const clone = cloneVNode(vnode)
124124
clone.fnContext = contextVm
125125
clone.fnOptions = options
126+
if (process.env.NODE_ENV !== 'production') {
127+
;(clone.devtoolsMeta = clone.devtoolsMeta || {}).renderContext = renderContext
128+
}
126129
if (data.slot) {
127130
(clone.data || (clone.data = {})).slot = data.slot
128131
}

src/core/vdom/vnode.js

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export default class VNode {
2626
ssrContext: Object | void;
2727
fnContext: Component | void; // real context vm for functional nodes
2828
fnOptions: ?ComponentOptions; // for SSR caching
29+
devtoolsMeta: ?Object; // used to store functional render context for devtools
2930
fnScopeId: ?string; // functional scope id support
3031

3132
constructor (

0 commit comments

Comments
 (0)