-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(solid): run stream in request event async ctx
Signed-off-by: Marc MacLeod <[email protected]>
- Loading branch information
Showing
6 changed files
with
26 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@ssrx/solid': patch | ||
--- | ||
|
||
Wrap the stream in the solid request event async ctx so that cache function from solid-router can be used in v0.11+. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
import type { RenderToStreamFn } from '@ssrx/renderer/server'; | ||
import { injectIntoStream } from '@ssrx/streaming'; | ||
import { renderToStream as renderToSolidStream } from 'solid-js/web'; | ||
/* @ts-expect-error no types */ | ||
import { provideRequestEvent } from 'solid-js/web/storage'; | ||
|
||
export const renderToStream: RenderToStreamFn<{ | ||
nonce?: string; | ||
renderId?: string; | ||
onCompleteShell?: (info: { write: (v: string) => void }) => void; | ||
onCompleteAll?: (info: { write: (v: string) => void }) => void; | ||
}> = async ({ req, app, injectToStream, opts }) => { | ||
const stream = renderToSolidStream(() => app(), opts); | ||
const { readable, writable } = new TransformStream(); | ||
stream.pipeTo(writable); | ||
return provideRequestEvent(req, () => { | ||
const stream = renderToSolidStream(() => app(), opts); | ||
const { readable, writable } = new TransformStream(); | ||
stream.pipeTo(writable); | ||
|
||
return { | ||
stream: injectToStream ? injectIntoStream(req, readable, injectToStream) : readable, | ||
statusCode: () => 200, | ||
}; | ||
return { | ||
stream: injectToStream ? injectIntoStream(req, readable, injectToStream) : readable, | ||
statusCode: () => 200, | ||
}; | ||
}); | ||
}; |
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