Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
5841aac8
Unverified
Commit
5841aac8
authored
Jul 13, 2022
by
Shu Ding
Committed by
GitHub
Jul 13, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove the hide-fouc tag earlier (#38614)
fix: remove hide-fouc tag earlier
parent
102cef0f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
10 deletions
+16
-10
app-index.tsx
packages/next/client/app-index.tsx
+16
-10
No files found.
packages/next/client/app-index.tsx
View file @
5841aac8
...
...
@@ -164,11 +164,14 @@ async function loadCss(cssChunkInfoJson: string) {
return
Promise
.
resolve
()
}
function
createLoadFlightCssStream
()
{
function
createLoadFlightCssStream
(
onFlightCssLoaded
:
()
=>
void
)
{
const
promises
:
Promise
<
any
>
[]
=
[]
let
cssFlushed
=
false
const
loadCssFromStreamData
=
(
data
:
string
)
=>
{
if
(
data
.
startsWith
(
'CSS'
))
{
const
cssJson
=
data
.
slice
(
4
).
trim
()
loadCss
(
cssJson
)
promises
.
push
(
loadCss
(
cssJson
)
)
}
}
...
...
@@ -182,6 +185,11 @@ function createLoadFlightCssStream() {
loadCssFromStreamData
(
buf
)
}
else
{
controller
.
enqueue
(
new
TextEncoder
().
encode
(
buf
))
if
(
!
cssFlushed
)
{
cssFlushed
=
true
Promise
.
all
(
promises
).
then
(()
=>
onFlightCssLoaded
())
}
}
}
}
...
...
@@ -202,7 +210,10 @@ function createLoadFlightCssStream() {
return
loadCssFromFlight
}
function
useInitialServerResponse
(
cacheKey
:
string
)
{
function
useInitialServerResponse
(
cacheKey
:
string
,
onFlightCssLoaded
:
()
=>
void
)
{
const
response
=
rscCache
.
get
(
cacheKey
)
if
(
response
)
return
response
...
...
@@ -213,7 +224,7 @@ function useInitialServerResponse(cacheKey: string) {
})
const
newResponse
=
createFromReadableStream
(
readable
.
pipeThrough
(
createLoadFlightCssStream
())
readable
.
pipeThrough
(
createLoadFlightCssStream
(
onFlightCssLoaded
))
)
rscCache
.
set
(
cacheKey
,
newResponse
)
...
...
@@ -230,12 +241,7 @@ function ServerRoot({
React
.
useEffect
(()
=>
{
rscCache
.
delete
(
cacheKey
)
})
React
.
useEffect
(()
=>
{
if
(
process
.
env
.
NODE_ENV
===
'development'
)
{
onFlightCssLoaded
?.()
}
},
[
onFlightCssLoaded
])
const
response
=
useInitialServerResponse
(
cacheKey
)
const
response
=
useInitialServerResponse
(
cacheKey
,
onFlightCssLoaded
)
const
root
=
response
.
readRoot
()
return
root
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment