Skip to content

Commit

Permalink
Remove dependency on react-streaming (#1205)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlecAivazis committed Oct 6, 2023
1 parent e6c7883 commit e05f1c2
Show file tree
Hide file tree
Showing 35 changed files with 994 additions and 135 deletions.
5 changes: 5 additions & 0 deletions .changeset/stupid-walls-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'houdini-react': patch
---

Fix invalid import during dev
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ packages/*/package.json

packages/houdini-svelte/src/runtime/index.ts
packages/create-houdini/**/houdini.config.js
packages/houdini-react/src/runtime/server/**/*
3 changes: 1 addition & 2 deletions e2e/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
"houdini-adapter-cloudflare": "workspace:^",
"houdini-react": "workspace:^",
"react": "^18.3.0-canary-d6dcad6a8-20230914",
"react-dom": "^18.3.0-canary-d6dcad6a8-20230914",
"react-streaming": "^0.3.10"
"react-dom": "^18.3.0-canary-d6dcad6a8-20230914"
},
"devDependencies": {
"@types/react": "^18.0.27",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"houdini-react": "^HOUDINI_VERSION",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-streaming": "^0.3.14",
"graphql-yoga": "4.0.4",
"graphql": "15.8.0",
"@whatwg-node/server": "^0.9.14"
Expand Down
1 change: 0 additions & 1 deletion packages/create-houdini/templates/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"houdini-react": "^HOUDINI_VERSION",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-streaming": "^0.3.14",
"graphql-yoga": "4.0.4",
"graphql": "15.8.0",
"@whatwg-node/server": "^0.9.14"
Expand Down
3 changes: 1 addition & 2 deletions packages/houdini-adapter-cloudflare/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@
"houdini": "workspace:^",
"itty-router": "^4.0.23",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-streaming": "^0.3.14"
"react-dom": "^18.2.0"
},
"files": [
"build"
Expand Down
6 changes: 3 additions & 3 deletions packages/houdini-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@types/cookies": "^0.7.7",
"@types/estraverse": "^5.1.2",
"@types/express": "^4.17.17",
"@types/react-dom": "^18.0.10",
"@types/react-dom": "^18.0.11",
"next": "^13.0.1",
"scripts": "workspace:^"
},
Expand All @@ -43,7 +43,7 @@
"graphql-yoga": "^4.0.4",
"houdini": "workspace:^",
"react": "^18.2.0",
"react-streaming": "^0.3.9",
"react-dom": "^18.2.0",
"recast": "^0.23.1",
"rollup": "^3.7.4",
"use-deep-compare-effect": "^1.8.1"
Expand All @@ -64,4 +64,4 @@
},
"main": "./build/plugin-cjs/index.js",
"types": "./build/plugin/index.d.ts"
}
}
2 changes: 1 addition & 1 deletion packages/houdini-react/src/plugin/codegen/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default (props) => (
import { Cache } from '$houdini/runtime/cache/cache'
import { serverAdapterFactory, _serverHandler } from '$houdini/runtime/router/server'
import { HoudiniClient } from '$houdini/runtime/client'
import { renderToStream } from 'react-streaming/server'
import { renderToStream } from '$houdini/plugins/houdini-react/runtime/server'
import React from 'react'
import { router_cache } from '../../runtime/routing'
Expand Down
1 change: 0 additions & 1 deletion packages/houdini-react/src/plugin/vite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ export default {
assetFileNames: 'assets/[name].js',
entryFileNames: '[name].js',
},
external: ['react-streaming/server'],
},
}

Expand Down
9 changes: 8 additions & 1 deletion packages/houdini-react/src/runtime/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ export function Router({
last_variables,
session,
assetPrefix,
injectToStream,
}: {
initialURL: string
cache: Cache
session?: App.Session
assetPrefix: string
injectToStream?: (chunk: string) => void
} & RouterCache) {
return (
<RouterContextProvider
Expand All @@ -34,7 +36,12 @@ export function Router({
last_variables={last_variables}
session={session}
>
<RouterImpl initialURL={initialURL} manifest={manifest} assetPrefix={assetPrefix} />
<RouterImpl
initialURL={initialURL}
manifest={manifest}
assetPrefix={assetPrefix}
injectToStream={injectToStream}
/>
</RouterContextProvider>
)
}
13 changes: 7 additions & 6 deletions packages/houdini-react/src/runtime/routing/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { QueryArtifact } from '$houdini/runtime/lib/types'
import { find_match } from '$houdini/runtime/router/match'
import type { RouterManifest, RouterPageManifest } from '$houdini/runtime/router/types'
import React from 'react'
import { useStream } from 'react-streaming'

import { useDocumentStore } from '../hooks/useDocumentStore'
import { SuspenseCache, suspense_cache } from './cache'
Expand Down Expand Up @@ -35,10 +34,12 @@ export function Router({
manifest,
initialURL,
assetPrefix,
injectToStream,
}: {
manifest: RouterManifest<ComponentType>
initialURL?: string
assetPrefix: string
injectToStream?: undefined | ((chunk: string) => void)
}) {
// the current route is just a string in state.
const [current, setCurrent] = React.useState(() => {
Expand All @@ -58,6 +59,7 @@ export function Router({
page,
variables,
assetPrefix,
injectToStream,
})
// if we get this far, it's safe to load the component
const { component_cache } = useRouterContext()
Expand Down Expand Up @@ -129,10 +131,12 @@ function usePageData({
page,
variables,
assetPrefix,
injectToStream,
}: {
page: RouterPageManifest<ComponentType>
variables: GraphQLVariables
assetPrefix: string
injectToStream: undefined | ((chunk: string) => void)
}): {
loadData: (page: RouterPageManifest<ComponentType>, variables: {} | null) => void
loadComponent: (page: RouterPageManifest<ComponentType>) => void
Expand All @@ -148,9 +152,6 @@ function usePageData({
last_variables,
} = useRouterContext()

// get a reference to the current stream
const stream = useStream()

// grab the current session value
const session = useSession()

Expand Down Expand Up @@ -188,7 +189,7 @@ function usePageData({
// if we are building up a stream (on the server), we want to add something
// to the client that resolves the pending request with the
// data that we just got
stream?.injectToStream(`
injectToStream?.(`
<script>
window.__houdini__cache__?.hydrate(${cache.serialize()}, window.__houdini__hydration__layer)
Expand Down Expand Up @@ -290,7 +291,7 @@ function usePageData({
artifact_cache.set(artifact_id, artifact)

// add a script to load the artifact
stream?.injectToStream(`
injectToStream?.(`
<script type="module" src="${assetPrefix}/artifacts/${artifact.name}.js" async=""></script>
`)

Expand Down
19 changes: 19 additions & 0 deletions packages/houdini-react/src/runtime/server/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
This directory is largely copied from https://github.com/brillout/react-streaming and adapted to fit the needs of this project. It is subject to the MIT license, found [here](https://github.com/brillout/react-streaming/blob/main/LICENSE.md). Duplicated below for reference:
MIT License
Copyright (c) 2022-present Romuald Brillout
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// We don't import from ./utils.ts because utils/debug.js contains a !isBrowser() assertion
import { renderToStream } from './renderToStream'
import type { InjectToStream } from './renderToStream/createBuffer'

export { renderToStream }
export type { InjectToStream }
Loading

0 comments on commit e05f1c2

Please sign in to comment.