From 965376fe2f29d2c7eb3f9380803dd87c53a5f094 Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Tue, 12 Jul 2022 22:23:38 +0200 Subject: [PATCH] fix buffering --- packages/next/client/app-index.tsx | 3 ++- packages/next/client/components/app-router.client.tsx | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/next/client/app-index.tsx b/packages/next/client/app-index.tsx index 89d280b528f3..2b5d0036e608 100644 --- a/packages/next/client/app-index.tsx +++ b/packages/next/client/app-index.tsx @@ -173,7 +173,7 @@ function useInitialServerResponse(cacheKey: string) { const loadCssFromStreamData = (data: string) => { if (data.startsWith('CSS:')) { - loadCss(data.slice(4)) + loadCss(data.slice(4).trim()) } } @@ -195,6 +195,7 @@ function useInitialServerResponse(cacheKey: string) { } if (buffer && !buffer.startsWith('CSS:')) { controller.enqueue(new TextEncoder().encode(buffer)) + buffer = '' } }, flush() { diff --git a/packages/next/client/components/app-router.client.tsx b/packages/next/client/components/app-router.client.tsx index 4a81bdc3e38b..9b571472108e 100644 --- a/packages/next/client/components/app-router.client.tsx +++ b/packages/next/client/components/app-router.client.tsx @@ -33,7 +33,7 @@ async function loadCss(cssChunkInfoJson: string) { const loadCssFromStreamData = (data: string) => { if (data.startsWith('CSS:')) { - loadCss(data.slice(4)) + loadCss(data.slice(4).trim()) } } @@ -64,6 +64,7 @@ function fetchFlight(url: URL, flightRouterStateData: string): ReadableStream { } if (buffer && !buffer.startsWith('CSS:')) { controller.enqueue(new TextEncoder().encode(buffer)) + buffer = '' } }, flush() {