1- import "@vitejs/plugin-rsc/dist-DEF94lDJ" ;
2- import "@vitejs/plugin-rsc/browser-QWbIPyhO" ;
3- // @ts -ignore
4- import { createFromFetch , createFromReadableStream } from "@vitejs/plugin-rsc/browser-D8OPzpF5" ;
5- import "@vitejs/plugin-rsc/browser-LizIyxet" ;
6- // @ts -ignore
7- import { rscStream } from "@vitejs/plugin-rsc/client-edAdk2GF" ;
1+ import { hydrate as _hydrate } from '@vitejs/plugin-rsc/extra/browser'
2+ import { createFromFetch , createFromReadableStream } from "@vitejs/plugin-rsc/browser" ;
83import { useState , useMemo } from "react" ;
94import ReactDomClient from "react-dom/client" ;
105import { BundlerContext } from 'navigation-react' ;
116
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+
1229async function hydrate ( ) {
13- const initialPayload = await createFromReadableStream ( rscStream ) ;
30+ const initialPayload = await createFromReadableStream ( rscStream ) as any ;
1431 function Shell ( ) {
1532 const [ root , setRoot ] = useState ( initialPayload . root ) ;
1633 const bundler = useMemo ( ( ) => ( { setRoot, deserialize : fetchRSC } ) , [ ] ) ;
@@ -23,7 +40,7 @@ async function hydrate() {
2340 ReactDomClient . hydrateRoot ( document , < Shell /> ) ;
2441}
2542async function fetchRSC ( url : string , { body, ...options } : any ) {
26- const payload = await createFromFetch ( fetch ( url , { ...options , body : JSON . stringify ( body ) , method : 'PUT' } ) ) ;
43+ const payload = await createFromFetch ( fetch ( url , { ...options , body : JSON . stringify ( body ) , method : 'PUT' } ) ) as any ;
2744 return payload . root ;
2845}
2946hydrate ( ) ;
0 commit comments