File tree Expand file tree Collapse file tree 1 file changed +17
-10
lines changed Expand file tree Collapse file tree 1 file changed +17
-10
lines changed Original file line number Diff line number Diff line change @@ -219,20 +219,27 @@ const depthSort = (a, b) => a._vnode._depth - b._vnode._depth;
219219
220220/** Flush the render queue by rerendering all queued components */
221221function process ( ) {
222- let c ;
223- rerenderQueue . sort ( depthSort ) ;
222+ let c ,
223+ l = 1 ;
224+
224225 // Don't update `renderCount` yet. Keep its value non-zero to prevent unnecessary
225226 // process() calls from getting scheduled while `queue` is still being consumed.
226- while ( ( c = rerenderQueue . shift ( ) ) ) {
227+ while ( rerenderQueue . length ) {
228+ // Keep the rerender queue sorted by (depth, insertion order). The queue
229+ // will initially be sorted on the first iteration only if it has more than 1 item.
230+ //
231+ // New items can be added to the queue e.g. when rerendering a provider, so we want to
232+ // keep the order from top to bottom with those new items so we can handle them in a
233+ // single pass
234+ if ( rerenderQueue . length > l ) {
235+ rerenderQueue . sort ( depthSort ) ;
236+ }
237+
238+ c = rerenderQueue . shift ( ) ;
239+ l = rerenderQueue . length ;
240+
227241 if ( c . _dirty ) {
228- let renderQueueLength = rerenderQueue . length ;
229242 renderComponent ( c ) ;
230- if ( rerenderQueue . length > renderQueueLength ) {
231- // When i.e. rerendering a provider additional new items can be injected, we want to
232- // keep the order from top to bottom with those new items so we can handle them in a
233- // single pass
234- rerenderQueue . sort ( depthSort ) ;
235- }
236243 }
237244 }
238245 process . _rerenderCount = 0 ;
You can’t perform that action at this time.
0 commit comments