Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add useFlushEffect hook #31223

Closed
wants to merge 36 commits into from
Closed

Conversation

devknoll
Copy link
Contributor

@devknoll devknoll commented Nov 9, 2021

Implements #30997

@ijjk

This comment has been minimized.

@ijjk

This comment has been minimized.

@ijjk

This comment has been minimized.

@ijjk

This comment has been minimized.

kodiakhq bot pushed a commit that referenced this pull request Nov 18, 2021
Simplifies `renderToWebStream` a little bit for #31223
@ijjk

This comment has been minimized.

@ijjk

This comment has been minimized.

@ijjk

This comment has been minimized.

@ijjk

This comment has been minimized.

kodiakhq bot pushed a commit that referenced this pull request Nov 19, 2021
Extracted from #31223.

We need to move the root `<div id="__next">` wrapper to be rendered as part of the page content, rather than the`Document`, so that flush effects (like styles) are flushed before (or after) the div, rather than inside, where they would cause hydration mismatches.
@ijjk
Copy link
Member

ijjk commented Nov 19, 2021

Failing test suites

Commit: ce0cc20

test/integration/document-functional-flush-effect/test/index.test.js

  • Functional Custom Document > development mode > supports custom flush handlers
Expand output

● Functional Custom Document › development mode › supports custom flush handlers

expect(received).toMatch(expected)

Expected pattern: /<foo><\/foo><bar><\/bar><span>Hello World!<\/span>/
Received string:  "<!DOCTYPE html><html><head><style data-next-hide-fouc=\"true\">body{display:none}</style><noscript data-next-hide-fouc=\"true\"><style>body{display:block}</style></noscript><meta charSet=\"utf-8\"/><meta name=\"viewport\" content=\"width=device-width\"/><meta name=\"next-head-count\" content=\"2\"/><noscript data-n-css=\"\"></noscript><script defer=\"\" nomodule=\"\" src=\"/_next/static/chunks/polyfills.js?ts=1637339867896\"></script><script src=\"/_next/static/chunks/webpack.js?ts=1637339867896\" defer=\"\"></script><script src=\"/_next/static/chunks/main.js?ts=1637339867896\" defer=\"\"></script><script src=\"/_next/static/chunks/pages/_app.js?ts=1637339867896\" defer=\"\"></script><script src=\"/_next/static/chunks/pages/index.js?ts=1637339867896\" defer=\"\"></script><script src=\"/_next/static/development/_buildManifest.js?ts=1637339867896\" defer=\"\"></script><script src=\"/_next/static/development/_ssgManifest.js?ts=1637339867896\" defer=\"\"></script><script src=\"/_next/static/development/_middlewareManifest.js?ts=1637339867896\" defer=\"\"></script><noscript id=\"__next_css__DO_NOT_USE__\"></noscript></head><body><foo></foo><bar></bar><div id=\"__next\" data-reactroot=\"\"><span>Hello World!</span></div><script src=\"/_next/static/chunks/react-refresh.js?ts=1637339867896\"></script><script id=\"__NEXT_DATA__\" type=\"application/json\">{\"props\":{\"pageProps\":{}},\"page\":\"/\",\"query\":{},\"buildId\":\"development\",\"nextExport\":true,\"autoExport\":true,\"isFallback\":false,\"scriptLoader\":[]}</script></body></html>"

  15 |     })
  16 |
> 17 |     afterAll(() => killApp(app))
     |                          ^
  18 |
  19 |     it('supports custom flush handlers', async () => {
  20 |       const html = await renderViaHTTP(appPort, '/')

  at Object.<anonymous> (integration/document-functional-flush-effect/test/index.test.js:17:26)

@ijjk
Copy link
Member

ijjk commented Nov 19, 2021

Stats from current PR

Default Build (Decrease detected ✓)
General Overall increase ⚠️
vercel/next.js canary azukaru/next.js x-add-use-flush-handler Change
buildDuration 18s 17.8s -183ms
buildDurationCached 3.5s 3.7s ⚠️ +153ms
nodeModulesSize 339 MB 339 MB ⚠️ +7.56 kB
Page Load Tests Overall decrease ⚠️
vercel/next.js canary azukaru/next.js x-add-use-flush-handler Change
/ failed reqs 0 0
/ total time (seconds) 2.948 2.958 ⚠️ +0.01
/ avg req/sec 848.03 845.2 ⚠️ -2.83
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.36 1.393 ⚠️ +0.03
/error-in-render avg req/sec 1838.21 1794.24 ⚠️ -43.97
Client Bundles (main, webpack, commons)
vercel/next.js canary azukaru/next.js x-add-use-flush-handler Change
450.HASH.js gzip 179 B 179 B
framework-HASH.js gzip 42.2 kB 42.2 kB
main-HASH.js gzip 28.3 kB 28.3 kB
webpack-HASH.js gzip 1.45 kB 1.45 kB
Overall change 72.2 kB 72.2 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary azukaru/next.js x-add-use-flush-handler Change
polyfills-HASH.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages
vercel/next.js canary azukaru/next.js x-add-use-flush-handler Change
_app-HASH.js gzip 1.37 kB 1.37 kB
_error-HASH.js gzip 194 B 194 B
amp-HASH.js gzip 312 B 312 B
css-HASH.js gzip 327 B 327 B
dynamic-HASH.js gzip 2.38 kB 2.38 kB
head-HASH.js gzip 350 B 350 B
hooks-HASH.js gzip 635 B 635 B
image-HASH.js gzip 4.45 kB 4.45 kB
index-HASH.js gzip 263 B 263 B
link-HASH.js gzip 1.87 kB 1.87 kB
routerDirect..HASH.js gzip 321 B 321 B
script-HASH.js gzip 383 B 383 B
withRouter-HASH.js gzip 318 B 318 B
85e02e95b279..7e3.css gzip 107 B 107 B
Overall change 13.3 kB 13.3 kB
Client Build Manifests
vercel/next.js canary azukaru/next.js x-add-use-flush-handler Change
_buildManifest.js gzip 460 B 460 B
Overall change 460 B 460 B
Rendered Page Sizes
vercel/next.js canary azukaru/next.js x-add-use-flush-handler Change
index.html gzip 532 B 532 B
link.html gzip 545 B 545 B
withRouter.html gzip 526 B 526 B
Overall change 1.6 kB 1.6 kB

Default Build with SWC (Increase detected ⚠️)
General Overall increase ⚠️
vercel/next.js canary azukaru/next.js x-add-use-flush-handler Change
buildDuration 19.6s 19.4s -239ms
buildDurationCached 3.6s 3.6s -39ms
nodeModulesSize 339 MB 339 MB ⚠️ +7.56 kB
Page Load Tests Overall increase ✓
vercel/next.js canary azukaru/next.js x-add-use-flush-handler Change
/ failed reqs 0 0
/ total time (seconds) 2.905 2.889 -0.02
/ avg req/sec 860.44 865.41 +4.97
/error-in-render failed reqs 0 0
/error-in-render total time (seconds) 1.398 1.368 -0.03
/error-in-render avg req/sec 1788.4 1827.34 +38.94
Client Bundles (main, webpack, commons)
vercel/next.js canary azukaru/next.js x-add-use-flush-handler Change
450.HASH.js gzip 179 B 179 B
framework-HASH.js gzip 42.3 kB 42.3 kB
main-HASH.js gzip 28.6 kB 28.6 kB
webpack-HASH.js gzip 1.44 kB 1.44 kB
Overall change 72.5 kB 72.5 kB
Legacy Client Bundles (polyfills)
vercel/next.js canary azukaru/next.js x-add-use-flush-handler Change
polyfills-HASH.js gzip 31 kB 31 kB
Overall change 31 kB 31 kB
Client Pages
vercel/next.js canary azukaru/next.js x-add-use-flush-handler Change
_app-HASH.js gzip 1.35 kB 1.35 kB
_error-HASH.js gzip 180 B 180 B
amp-HASH.js gzip 305 B 305 B
css-HASH.js gzip 321 B 321 B
dynamic-HASH.js gzip 2.38 kB 2.38 kB
head-HASH.js gzip 342 B 342 B
hooks-HASH.js gzip 622 B 622 B
image-HASH.js gzip 4.47 kB 4.47 kB
index-HASH.js gzip 256 B 256 B
link-HASH.js gzip 1.91 kB 1.91 kB
routerDirect..HASH.js gzip 314 B 314 B
script-HASH.js gzip 375 B 375 B
withRouter-HASH.js gzip 309 B 309 B
85e02e95b279..7e3.css gzip 107 B 107 B
Overall change 13.2 kB 13.2 kB
Client Build Manifests
vercel/next.js canary azukaru/next.js x-add-use-flush-handler Change
_buildManifest.js gzip 459 B 459 B
Overall change 459 B 459 B
Rendered Page Sizes
vercel/next.js canary azukaru/next.js x-add-use-flush-handler Change
index.html gzip 532 B 532 B
link.html gzip 545 B 545 B
withRouter.html gzip 526 B 526 B
Overall change 1.6 kB 1.6 kB
Commit: ce0cc20

natew pushed a commit to natew/next.js that referenced this pull request Feb 16, 2022
Simplifies `renderToWebStream` a little bit for vercel#31223
natew pushed a commit to natew/next.js that referenced this pull request Feb 16, 2022
Extracted from vercel#31223.

We need to move the root `<div id="__next">` wrapper to be rendered as part of the page content, rather than the`Document`, so that flush effects (like styles) are flushed before (or after) the div, rather than inside, where they would cause hydration mismatches.
@devknoll devknoll closed this Feb 28, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants