File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,16 @@ import type {
77 ContextStore
88} from '../types'
99
10+ /* The context is kept as a Map from a Context value to the current
11+ value on the React element tree.
12+ The legacy context is kept as a simple object.
13+ When the tree is being walked modifications are made by assigning
14+ new legacy context maps or new context values.
15+ These changes are kept in the `prev` variables and must be flushed
16+ before continuing to walk the tree.
17+ After walking the children they can be restored.
18+ This way the context recursively restores itself on the way up. */
19+
1020type ContextEntry = [ AbstractContext , mixed ]
1121
1222let currentContextStore : ContextStore = new Map ( )
Original file line number Diff line number Diff line change @@ -152,11 +152,13 @@ const visitChild = (
152152 visitor : Visitor
153153) = > {
154154 const children = visitElement ( child , queue , visitor )
155+ // Flush the context changes
155156 const prevMap = flushPrevContextMap ( )
156157 const prevStore = flushPrevContextStore ( )
157158
158159 visitChildren ( children , queue , visitor )
159160
161+ // Restore context changes after children have been walked
160162 if ( prevMap !== undefined ) {
161163 restoreContextMap ( prevMap )
162164 }
You can’t perform that action at this time.
0 commit comments