Skip to content

Commit

Permalink
core util
Browse files Browse the repository at this point in the history
  • Loading branch information
AlecAivazis committed Feb 10, 2024
1 parent 1933fe3 commit d753bf1
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 44 deletions.
102 changes: 59 additions & 43 deletions packages/houdini-react/src/plugin/codegen/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,49 +70,65 @@ export const on_render =
return new Response('not found', { status: 404 })
}
// this is what hangs
const {
readable,
injectToStream,
pipe: pipeTo,
} = await renderToStream(
React.createElement(App, {
initialURL: url,
cache: cache,
session: session,
assetPrefix: assetPrefix,
manifest: manifest,
...router_cache()
}),
{
webStream: production,
userAgent: 'Vite',
}
)
// add the initial scripts to the page
injectToStream(\`
<script>
window.__houdini__initial__cache__ = \${cache.serialize()};
window.__houdini__initial__session__ = \${JSON.stringify(session)};
</script>
\${documentPremable ?? ''}
<!--
add a virtual module that hydrates the client and sets up the initial pending cache.
the dynamic extension is to support dev which sees the raw jsx, and production which sees the bundled asset
-->
<script type="module" src="\${assetPrefix}/pages/\${match.id}.\${production ? 'js' : 'jsx'}" async=""></script>
\`)
if (pipeTo && pipe) {
pipeTo(pipe)
return true
} else {
return new Response(readable)
}
const stream = React.renderToReadableStream(React.createElement(App, {
initialURL: url,
cache: cache,
session: session,
assetPrefix: assetPrefix,
manifest: manifest,
...router_cache()
}))
// // this is what hangs
// const {
// readable,
// injectToStream,
// pipe: pipeTo,
// } = await renderToStream(
// React.createElement(App, {
// initialURL: url,
// cache: cache,
// session: session,
// assetPrefix: assetPrefix,
// manifest: manifest,
// ...router_cache()
// }),
// {
// webStream: production,
// userAgent: 'Vite',
// }
// )
// // add the initial scripts to the page
// injectToStream(\`
// <script>
// window.__houdini__initial__cache__ = \${cache.serialize()};
// window.__houdini__initial__session__ = \${JSON.stringify(session)};
// </script>
// \${documentPremable ?? ''}
// <!--
// add a virtual module that hydrates the client and sets up the initial pending cache.
// the dynamic extension is to support dev which sees the raw jsx, and production which sees the bundled asset
// -->
// <script type="module" src="\${assetPrefix}/pages/\${match.id}.\${production ? 'js' : 'jsx'}" async=""></script>
// \`)
// if (pipeTo && pipe) {
// pipeTo(pipe)
// return true
// } else {
// return new Response(readable)
// }
return new Response(stream, {
headers: { 'content-type': 'text/html' },
});
}
export function createServerAdapter(options) {
Expand Down
1 change: 0 additions & 1 deletion packages/houdini-react/src/runtime/routing/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export function Router({
assetPrefix: string
injectToStream?: undefined | ((chunk: string) => void)
}) {
return <div>hello!</div>
// the current route is just a string in state.
const [currentURL, setCurrentURL] = React.useState(() => {
return initialURL || window.location.pathname
Expand Down

0 comments on commit d753bf1

Please sign in to comment.