-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad99881
commit 74b5a92
Showing
15 changed files
with
165 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,26 @@ | ||
server | ||
loader | ||
notFound -> render | ||
redirect -> render | ||
render | ||
notFound -> set fallbackComponent to notFoundComponent, set routeState to {status: 'notFound'}, throw | ||
redirect -> throw | ||
|
||
client | ||
loader | ||
notFound -> render | ||
redirect -> render | ||
render | ||
notFound -> throw | ||
redirect -> throw | ||
|
||
|
||
|
||
|
||
|
||
|
||
```tsx | ||
const history = createBrowserHistory(); | ||
|
||
const router = new Router({ | ||
ssr: { stateStringifier } | ||
routes: [] | ||
}); | ||
|
||
// client | ||
startSSRHydration(router, location, { stateParser }); | ||
|
||
|
||
|
||
|
||
|
||
router.navigate(location); | ||
|
||
|
||
|
||
RouteMatch { route, params } | ||
RouteState { status, data, error, url } // marshalled | ||
RouteContent { component, state } | ||
Slot { router, routeMatch, routeContent } | ||
|
||
|
||
|
||
|
||
|
||
createRoute('/foo', props => props.router.redirect(loginRoute.getLocation({ url: props.router.history.url })) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
hydrateRouter(router, history.location); | ||
``` | ||
|
||
```tsx | ||
const history = createMemoryHistory(request.url); | ||
|
||
const router = new SSRRouter({ | ||
routes: [] | ||
}); | ||
|
||
let html; | ||
do { | ||
html = renderToString(<App/>); | ||
} while (await manager.hasChanges() || await router.hasChanges()); | ||
|
||
html += router.nextHydrationChunk(); | ||
|
||
respose.end(html); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Writable } from 'stream'; | ||
import { SSRRouter, SSRRouterOptions } from './SSRRouter'; | ||
|
||
export class PipeableSSRRouter<Context> extends SSRRouter<Context> { | ||
readonly stream: NodeJS.WritableStream; | ||
|
||
constructor(stream: NodeJS.WritableStream, options: SSRRouterOptions<Context>) { | ||
super(options); | ||
|
||
this.stream = new Writable({ | ||
write: (chunk, encoding, callback) => { | ||
stream.write(chunk, encoding, error => { | ||
if (error) { | ||
callback(error); | ||
return; | ||
} | ||
|
||
const hydrationChunk = this.nextHydrationChunk(); | ||
|
||
if (hydrationChunk !== '') { | ||
stream.write(hydrationChunk, callback); | ||
return; | ||
} | ||
|
||
callback(); | ||
}); | ||
}, | ||
|
||
final: callback => { | ||
stream.end(callback); | ||
}, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { SSRRouter, SSRRouterOptions } from './SSRRouter'; | ||
|
||
export class ReadableSSRRouter<Context = any> extends SSRRouter<Context> implements ReadableWritablePair { | ||
readonly readable: ReadableStream; | ||
readonly writable: WritableStream; | ||
|
||
constructor(options: SSRRouterOptions<Context>) { | ||
super(options); | ||
|
||
const transformer = new TransformStream({ | ||
transform: (chunk, controller) => { | ||
controller.enqueue(chunk); | ||
|
||
const hydrationChunk = this.nextHydrationChunk(); | ||
|
||
if (hydrationChunk !== '') { | ||
controller.enqueue(hydrationChunk); | ||
} | ||
}, | ||
}); | ||
|
||
this.readable = transformer.readable; | ||
this.writable = transformer.writable; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { RouteState } from '../__loadRoute'; | ||
import { RouterOptions } from '../__types'; | ||
import { Router } from '../Router'; | ||
|
||
export interface SSRRouterOptions<Context> extends RouterOptions<Context> { | ||
stateStringifier?: (state: RouteState) => string; | ||
nonce?: string; | ||
} | ||
|
||
export class SSRRouter<Context = any> extends Router<Context> { | ||
hasChanges(): Promise<boolean> { | ||
return Promise.resolve(false); | ||
} | ||
|
||
nextHydrationChunk(): string { | ||
return ''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
declare global { | ||
interface Window { | ||
__REACT_CORSAIR_SSR_STATE__?: { set(routeIndex: number, stateStr: string): void }; | ||
} | ||
} | ||
|
||
export {}; |
Oops, something went wrong.