File tree Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -116,12 +116,25 @@ describe('api: createApp', () => {
116116 const app = createApp ( {
117117 setup ( ) {
118118 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+
119130 return ( ) => h ( 'div' )
120131 } ,
121132 } )
122133 app . provide ( 'foo' , 1 )
123134
124135 expect ( app . runWithContext ( ( ) => inject ( 'foo' ) ) ) . toBe ( 1 )
136+ const root = nodeOps . createElement ( 'div' )
137+ app . mount ( root )
125138
126139 expect (
127140 app . runWithContext ( ( ) => {
Original file line number Diff line number Diff line change @@ -56,11 +56,14 @@ export function inject(
5656 // #2400
5757 // to support `app.use` plugins,
5858 // 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
6467
6568 if ( provides && ( key as string | symbol ) in provides ) {
6669 // TS doesn't allow symbol as index type
You can’t perform that action at this time.
0 commit comments