Skip to content

Commit 18212ca

Browse files
authored
[Fizz] Outline if a boundary would add too many bytes to the next completion (facebook#33029)
Follow up to facebook#33027. This enhances the heuristic so that we accumulate the size of the currently written boundaries. Starting from the size of the root (minus preamble) for the shell. This ensures that if you have many small boundaries they don't all continue to get inlined. For example, you can wrap each paragraph in a document in a Suspense boundary to regain document streaming capabilities if that's what you want. However, one consideration is if it's worth producing a fallback at all. Maybe if it's like `null` it's free but if it's like a whole alternative page, then it's not. It's possible to have completely useless Suspense boundaries such as when you nest several directly inside each other. So this uses a limit of at least 500 bytes of the content itself for it to be worth outlining at all. It also can't be too small because then for example a long list of paragraphs can never be outlined. In the fixture I straddle this limit so some paragraphs are too small to be considered. An unfortunate effect of that is that you can end up with some of them not being outlined which means that they appear out of order. SuspenseList is supposed to address that but it's unfortunate. The limit is still fairly high though so it's unlikely that by default you'd start outlining anything within the viewport at all. I had to reduce the `progressiveChunkSize` by an order of magnitude in my fixture to try it out properly.
1 parent 88b9767 commit 18212ca

File tree

4 files changed

+309
-247
lines changed

4 files changed

+309
-247
lines changed

fixtures/ssr/server/render.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class ThrottledWritable extends Writable {
1919
constructor(destination) {
2020
super();
2121
this.destination = destination;
22-
this.delay = 150;
22+
this.delay = 10;
2323
}
2424

2525
_write(chunk, encoding, callback) {
@@ -49,10 +49,10 @@ export default function render(url, res) {
4949
// Log fatal errors
5050
console.error('Fatal', error);
5151
});
52-
console.log('hello');
5352
let didError = false;
5453
const {pipe, abort} = renderToPipeableStream(<App assets={assets} />, {
5554
bootstrapScripts: [assets['main.js']],
55+
progressiveChunkSize: 1024,
5656
onShellReady() {
5757
// If something errored before we started streaming, we set the error code appropriately.
5858
res.statusCode = didError ? 500 : 200;

fixtures/ssr/src/components/Chrome.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,7 @@ export default class Chrome extends Component {
3939
{this.props.children}
4040
</Theme.Provider>
4141
</Suspense>
42-
<p>This should appear in the first paint.</p>
43-
<Suspense fallback="Loading...">
44-
<p>This content should not block paint.</p>
45-
<LargeContent />
46-
</Suspense>
42+
<LargeContent />
4743
<script
4844
dangerouslySetInnerHTML={{
4945
__html: `assetManifest = ${JSON.stringify(assets)};`,

0 commit comments

Comments
 (0)