diff --git a/packages/next/client/app-index.tsx b/packages/next/client/app-index.tsx index 74b0188408dc..715f257db3d0 100644 --- a/packages/next/client/app-index.tsx +++ b/packages/next/client/app-index.tsx @@ -72,6 +72,7 @@ const getCacheKey = () => { } const encoder = new TextEncoder() +const loadedCss: Set = new Set() let initialServerDataBuffer: string[] | undefined = undefined let initialServerDataWriter: ReadableStreamDefaultController | undefined = @@ -161,11 +162,12 @@ async function loadCss(cssChunkInfoJson: string) { } function createLoadFlightCssStream(callback?: () => Promise) { - const promises: Promise[] = [] + const cssLoadingPromises: Promise[] = [] const loadCssFromStreamData = (data: string) => { const seg = data.split(':') if (seg[0] === 'CSS') { - promises.push(loadCss(seg.slice(1).join(':'))) + const cssJson = seg.slice(1).join(':') + if (!loadedCss.has(cssJson)) cssLoadingPromises.push(loadCss(cssJson)) } } @@ -188,7 +190,7 @@ function createLoadFlightCssStream(callback?: () => Promise) { }) if (process.env.NODE_ENV === 'development') { - Promise.all(promises).then(() => { + Promise.all(cssLoadingPromises).then(() => { // TODO: find better timing for css injection setTimeout(() => { callback?.() @@ -247,11 +249,9 @@ function Root({ children }: React.PropsWithChildren<{}>): React.ReactElement { return children as React.ReactElement } -function RSCComponent({ onFlightCssLoaded }: { onFlightCssLoaded: any }) { +function RSCComponent(props: any) { const cacheKey = getCacheKey() - return ( - - ) + return } export async function hydrate(opts?: { diff --git a/packages/next/server/app-render.tsx b/packages/next/server/app-render.tsx index f073155f3953..0f391dc7e9ec 100644 --- a/packages/next/server/app-render.tsx +++ b/packages/next/server/app-render.tsx @@ -131,7 +131,6 @@ function useFlightResponse( .pipeThrough(createPrefixStream(cssFlightData)) .getReader() const writer = writable.getWriter() - // let remainingFlightResponse = '' function process() { forwardReader.read().then(({ done, value }) => { if (!bootstrapped) { diff --git a/packages/next/server/node-web-streams-helper.ts b/packages/next/server/node-web-streams-helper.ts index c9569caf444d..ddbdedce2f60 100644 --- a/packages/next/server/node-web-streams-helper.ts +++ b/packages/next/server/node-web-streams-helper.ts @@ -140,20 +140,21 @@ export function createDevScriptTransformStream(): TransformStream< Uint8Array, Uint8Array > { - const headClosedTag = '' + let injected = false const foucTags = ` - ` + ` return new TransformStream({ transform(chunk, controller) { const content = decodeText(chunk) + let index + if (!injected && (index = content.indexOf('