File tree 2 files changed +21
-5
lines changed
2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -116,12 +116,25 @@ describe('api: createApp', () => {
116
116
const app = createApp ( {
117
117
setup ( ) {
118
118
provide ( 'foo' , 'should not be seen' )
119
+
120
+ // nested createApp
121
+ const childApp = createApp ( {
122
+ setup ( ) {
123
+ provide ( 'foo' , 'foo from child' )
124
+ } ,
125
+ } )
126
+
127
+ childApp . provide ( 'foo' , 2 )
128
+ expect ( childApp . runWithContext ( ( ) => inject ( 'foo' ) ) ) . toBe ( 2 )
129
+
119
130
return ( ) => h ( 'div' )
120
131
} ,
121
132
} )
122
133
app . provide ( 'foo' , 1 )
123
134
124
135
expect ( app . runWithContext ( ( ) => inject ( 'foo' ) ) ) . toBe ( 1 )
136
+ const root = nodeOps . createElement ( 'div' )
137
+ app . mount ( root )
125
138
126
139
expect (
127
140
app . runWithContext ( ( ) => {
Original file line number Diff line number Diff line change @@ -56,11 +56,14 @@ export function inject(
56
56
// #2400
57
57
// to support `app.use` plugins,
58
58
// fallback to appContext's `provides` if the instance is at root
59
- const provides = instance
60
- ? instance . parent == null
61
- ? instance . vnode . appContext && instance . vnode . appContext . provides
62
- : instance . parent . provides
63
- : currentApp ! . _context . provides
59
+ // #11488, in a nested createApp, prioritize using the provides from currentApp
60
+ const provides = currentApp
61
+ ? currentApp . _context . provides
62
+ : instance
63
+ ? instance . parent == null
64
+ ? instance . vnode . appContext && instance . vnode . appContext . provides
65
+ : instance . parent . provides
66
+ : undefined
64
67
65
68
if ( provides && ( key as string | symbol ) in provides ) {
66
69
// TS doesn't allow symbol as index type
You can’t perform that action at this time.
0 commit comments