Skip to content

Conversation

@kitten
Copy link
Contributor

@kitten kitten commented Apr 16, 2019

This implements a new "suspense frame" for yielding to the event loop, called a YieldFrame.

The problem with react-ssr-prepass' current visiting strategy is that like with react-dom's renderToString we never yield to the event loop. When a large app is rendered a lot of the work happens synchronously and blocks anything else from happening, even if the user chooses to use renderToNodeStream.

This reimplements the visitor to not be recursive and keep its own state. It then yields when visiting elements has been taking longer than 10ms. It does this by putting a YieldFrame onto the suspense queue that preserves the visitor's state and returns to the visitor like with other suspense frames.

kitten added 2 commits April 16, 2019 18:18
The problem with the current implementation is that like with
renderToString we never yield to the event loop. When a large
app is rendered a lot of the work happens synchronously.

This reimplements the visitor to not be recursive and yield
when it's taking longer than 10ms. It does this by putting
a YieldFrame onto the suspense queue that preserves the
visitor's state and returns to it like with other suspense
frames.
@kitten kitten force-pushed the event-loop-yielding branch from 8d2a284 to 3143304 Compare April 16, 2019 18:34
@codecov-io
Copy link

codecov-io commented Apr 16, 2019

Codecov Report

Merging #2 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master     #2   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           9      9           
  Lines         408    439   +31     
  Branches       66     72    +6     
=====================================
+ Hits          408    439   +31
Impacted Files Coverage Δ
src/internals/context.js 100% <100%> (ø) ⬆️
src/index.js 100% <100%> (ø) ⬆️
src/visitor.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 76ce717...b51f275. Read the comment docs.

@kitten kitten merged commit db0899d into master Apr 16, 2019
@kitten kitten deleted the event-loop-yielding branch April 16, 2019 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants