|
| 1 | +import * as ReactClient from '@vitejs/plugin-rsc/browser' |
1 | 2 | import { useState, useMemo } from "react";
|
2 | 3 | import ReactDOM from "react-dom/client";
|
3 |
| -import { hydrate as _hydrate } from '@vitejs/plugin-rsc/extra/browser' |
4 |
| -import { createFromFetch, createFromReadableStream } from "@vitejs/plugin-rsc/browser"; |
| 4 | +import { rscStream } from 'rsc-html-stream/client' |
| 5 | +import { createFromFetch } from "@vitejs/plugin-rsc/browser"; |
5 | 6 | import { BundlerContext } from 'navigation-react';
|
6 | 7 |
|
7 |
| -declare global{interface Window { __FLIGHT_DATA: any;}} |
8 |
| - |
9 |
| -let encoder = new TextEncoder(); |
10 |
| -let streamController: any; |
11 |
| -let rscStream = new ReadableStream({ start(controller) { |
12 |
| - if (typeof window === "undefined") return; |
13 |
| - let handleChunk = (chunk: any) => { |
14 |
| - if (typeof chunk === "string") controller.enqueue(encoder.encode(chunk)); |
15 |
| - else controller.enqueue(chunk); |
16 |
| - }; |
17 |
| - window.__FLIGHT_DATA ||= []; |
18 |
| - window.__FLIGHT_DATA.forEach(handleChunk); |
19 |
| - window.__FLIGHT_DATA.push = (chunk: any) => { |
20 |
| - handleChunk(chunk); |
21 |
| - }; |
22 |
| - streamController = controller; |
23 |
| -} }); |
24 |
| -if (typeof document !== "undefined" && document.readyState === "loading") document.addEventListener("DOMContentLoaded", () => { |
25 |
| - streamController?.close(); |
26 |
| -}); |
27 |
| -else streamController?.close(); |
28 | 8 |
|
29 | 9 | async function hydrate() {
|
30 |
| - const initialPayload = await createFromReadableStream(rscStream) as any; |
| 10 | + const initialPayload = await ReactClient.createFromReadableStream<any>(rscStream) |
31 | 11 | function Shell() {
|
32 | 12 | const [root, setRoot] = useState(initialPayload.root);
|
33 | 13 | const bundler = useMemo(() => ({setRoot, deserialize: fetchRSC}), []);
|
|
0 commit comments