houdini-react 2.0.0-next.4 → 2.0.0-next.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/houdini-react +173 -0
- package/package.json +63 -39
- package/postInstall.js +360 -0
- package/runtime/Link.tsx +81 -0
- package/runtime/client.ts +5 -0
- package/runtime/clientPlugin.ts +17 -0
- package/runtime/componentFields.ts +79 -0
- package/runtime/hooks/index.ts +9 -0
- package/runtime/hooks/recycleNodesInto.ts +60 -0
- package/runtime/hooks/useDeepCompareEffect.ts +93 -0
- package/runtime/hooks/useDocumentHandle.ts +238 -0
- package/runtime/hooks/useDocumentStore.ts +112 -0
- package/runtime/hooks/useDocumentSubscription.ts +65 -0
- package/runtime/hooks/useFragment.ts +101 -0
- package/runtime/hooks/useFragmentHandle.ts +191 -0
- package/runtime/hooks/useIsMounted.ts +14 -0
- package/runtime/hooks/useMutation.ts +70 -0
- package/runtime/hooks/useQuery.ts +12 -0
- package/runtime/hooks/useQueryHandle.ts +194 -0
- package/runtime/hooks/useSubscription.ts +12 -0
- package/runtime/hooks/useSubscriptionHandle.ts +38 -0
- package/runtime/hydration.tsx +155 -0
- package/runtime/index.tsx +66 -0
- package/runtime/manifest.ts +6 -0
- package/runtime/package.json +1 -0
- package/runtime/resolve-href.ts +14 -0
- package/runtime/routing/Router.tsx +959 -0
- package/runtime/routing/cache.ts +57 -0
- package/runtime/routing/errors.tsx +145 -0
- package/runtime/routing/index.ts +17 -0
- package/runtime/tsconfig.json +39 -0
- package/server/index.d.ts +1 -0
- package/server/index.js +4 -0
- package/server/react-streaming.d.js +0 -0
- package/vite/index.d.ts +3 -0
- package/vite/index.js +384 -0
- package/vite/transform.d.ts +11 -0
- package/vite/transform.js +90 -0
- package/README.md +0 -36
- package/build/plugin/codegen/entries/documentWrappers.d.ts +0 -6
- package/build/plugin/codegen/entries/fallbacks.d.ts +0 -5
- package/build/plugin/codegen/entries/index.d.ts +0 -16
- package/build/plugin/codegen/entries/pages.d.ts +0 -2
- package/build/plugin/codegen/index.d.ts +0 -17
- package/build/plugin/codegen/manifest.d.ts +0 -5
- package/build/plugin/codegen/render.d.ts +0 -7
- package/build/plugin/codegen/router.d.ts +0 -7
- package/build/plugin/codegen/typeRoot.d.ts +0 -5
- package/build/plugin/config.d.ts +0 -4
- package/build/plugin/dedent.d.ts +0 -1
- package/build/plugin/extract.d.ts +0 -6
- package/build/plugin/index.d.ts +0 -5
- package/build/plugin/state.d.ts +0 -3
- package/build/plugin/transform.d.ts +0 -6
- package/build/plugin/vite.d.ts +0 -27
- package/build/plugin-cjs/index.js +0 -90119
- package/build/plugin-cjs/package.json +0 -1
- package/build/plugin-esm/index.js +0 -90115
- package/build/runtime/client.d.ts +0 -3
- package/build/runtime/clientPlugin.d.ts +0 -3
- package/build/runtime/componentFields.d.ts +0 -9
- package/build/runtime/hooks/index.d.ts +0 -8
- package/build/runtime/hooks/useDeepCompareEffect.d.ts +0 -35
- package/build/runtime/hooks/useDocumentHandle.d.ts +0 -36
- package/build/runtime/hooks/useDocumentStore.d.ts +0 -11
- package/build/runtime/hooks/useDocumentSubscription.d.ts +0 -11
- package/build/runtime/hooks/useFragment.d.ts +0 -16
- package/build/runtime/hooks/useFragmentHandle.d.ts +0 -8
- package/build/runtime/hooks/useIsMounted.d.ts +0 -3
- package/build/runtime/hooks/useMutation.d.ts +0 -14
- package/build/runtime/hooks/useQuery.d.ts +0 -5
- package/build/runtime/hooks/useQueryHandle.d.ts +0 -10
- package/build/runtime/hooks/useSubscription.d.ts +0 -4
- package/build/runtime/hooks/useSubscriptionHandle.d.ts +0 -25
- package/build/runtime/index.d.ts +0 -14
- package/build/runtime/manifest.d.ts +0 -3
- package/build/runtime/routing/Router.d.ts +0 -62
- package/build/runtime/routing/cache.d.ts +0 -7
- package/build/runtime/routing/hooks.d.ts +0 -40
- package/build/runtime/routing/index.d.ts +0 -3
- package/build/runtime-cjs/client.d.ts +0 -3
- package/build/runtime-cjs/client.js +0 -25
- package/build/runtime-cjs/clientPlugin.d.ts +0 -3
- package/build/runtime-cjs/clientPlugin.js +0 -37
- package/build/runtime-cjs/componentFields.d.ts +0 -9
- package/build/runtime-cjs/componentFields.js +0 -83
- package/build/runtime-cjs/hooks/index.d.ts +0 -8
- package/build/runtime-cjs/hooks/index.js +0 -45
- package/build/runtime-cjs/hooks/useDeepCompareEffect.d.ts +0 -35
- package/build/runtime-cjs/hooks/useDeepCompareEffect.js +0 -76
- package/build/runtime-cjs/hooks/useDocumentHandle.d.ts +0 -36
- package/build/runtime-cjs/hooks/useDocumentHandle.js +0 -177
- package/build/runtime-cjs/hooks/useDocumentStore.d.ts +0 -11
- package/build/runtime-cjs/hooks/useDocumentStore.js +0 -76
- package/build/runtime-cjs/hooks/useDocumentSubscription.d.ts +0 -11
- package/build/runtime-cjs/hooks/useDocumentSubscription.js +0 -76
- package/build/runtime-cjs/hooks/useFragment.d.ts +0 -16
- package/build/runtime-cjs/hooks/useFragment.js +0 -102
- package/build/runtime-cjs/hooks/useFragmentHandle.d.ts +0 -8
- package/build/runtime-cjs/hooks/useFragmentHandle.js +0 -47
- package/build/runtime-cjs/hooks/useIsMounted.d.ts +0 -3
- package/build/runtime-cjs/hooks/useIsMounted.js +0 -38
- package/build/runtime-cjs/hooks/useMutation.d.ts +0 -14
- package/build/runtime-cjs/hooks/useMutation.js +0 -67
- package/build/runtime-cjs/hooks/useQuery.d.ts +0 -5
- package/build/runtime-cjs/hooks/useQuery.js +0 -32
- package/build/runtime-cjs/hooks/useQueryHandle.d.ts +0 -10
- package/build/runtime-cjs/hooks/useQueryHandle.js +0 -131
- package/build/runtime-cjs/hooks/useSubscription.d.ts +0 -4
- package/build/runtime-cjs/hooks/useSubscription.js +0 -32
- package/build/runtime-cjs/hooks/useSubscriptionHandle.d.ts +0 -25
- package/build/runtime-cjs/hooks/useSubscriptionHandle.js +0 -42
- package/build/runtime-cjs/index.d.ts +0 -14
- package/build/runtime-cjs/index.js +0 -88
- package/build/runtime-cjs/manifest.d.ts +0 -3
- package/build/runtime-cjs/manifest.js +0 -25
- package/build/runtime-cjs/package.json +0 -1
- package/build/runtime-cjs/routing/Router.d.ts +0 -62
- package/build/runtime-cjs/routing/Router.js +0 -540
- package/build/runtime-cjs/routing/cache.d.ts +0 -7
- package/build/runtime-cjs/routing/cache.js +0 -61
- package/build/runtime-cjs/routing/hooks.d.ts +0 -40
- package/build/runtime-cjs/routing/hooks.js +0 -93
- package/build/runtime-cjs/routing/index.d.ts +0 -3
- package/build/runtime-cjs/routing/index.js +0 -33
- package/build/runtime-esm/client.d.ts +0 -3
- package/build/runtime-esm/client.js +0 -5
- package/build/runtime-esm/clientPlugin.d.ts +0 -3
- package/build/runtime-esm/clientPlugin.js +0 -17
- package/build/runtime-esm/componentFields.d.ts +0 -9
- package/build/runtime-esm/componentFields.js +0 -59
- package/build/runtime-esm/hooks/index.d.ts +0 -8
- package/build/runtime-esm/hooks/index.js +0 -15
- package/build/runtime-esm/hooks/useDeepCompareEffect.d.ts +0 -35
- package/build/runtime-esm/hooks/useDeepCompareEffect.js +0 -41
- package/build/runtime-esm/hooks/useDocumentHandle.d.ts +0 -36
- package/build/runtime-esm/hooks/useDocumentHandle.js +0 -143
- package/build/runtime-esm/hooks/useDocumentStore.d.ts +0 -11
- package/build/runtime-esm/hooks/useDocumentStore.js +0 -42
- package/build/runtime-esm/hooks/useDocumentSubscription.d.ts +0 -11
- package/build/runtime-esm/hooks/useDocumentSubscription.js +0 -42
- package/build/runtime-esm/hooks/useFragment.d.ts +0 -16
- package/build/runtime-esm/hooks/useFragment.js +0 -67
- package/build/runtime-esm/hooks/useFragmentHandle.d.ts +0 -8
- package/build/runtime-esm/hooks/useFragmentHandle.js +0 -23
- package/build/runtime-esm/hooks/useIsMounted.d.ts +0 -3
- package/build/runtime-esm/hooks/useIsMounted.js +0 -14
- package/build/runtime-esm/hooks/useMutation.d.ts +0 -14
- package/build/runtime-esm/hooks/useMutation.js +0 -42
- package/build/runtime-esm/hooks/useQuery.d.ts +0 -5
- package/build/runtime-esm/hooks/useQuery.js +0 -8
- package/build/runtime-esm/hooks/useQueryHandle.d.ts +0 -10
- package/build/runtime-esm/hooks/useQueryHandle.js +0 -97
- package/build/runtime-esm/hooks/useSubscription.d.ts +0 -4
- package/build/runtime-esm/hooks/useSubscription.js +0 -8
- package/build/runtime-esm/hooks/useSubscriptionHandle.d.ts +0 -25
- package/build/runtime-esm/hooks/useSubscriptionHandle.js +0 -18
- package/build/runtime-esm/index.d.ts +0 -14
- package/build/runtime-esm/index.js +0 -48
- package/build/runtime-esm/manifest.d.ts +0 -3
- package/build/runtime-esm/manifest.js +0 -5
- package/build/runtime-esm/routing/Router.d.ts +0 -62
- package/build/runtime-esm/routing/Router.js +0 -499
- package/build/runtime-esm/routing/cache.d.ts +0 -7
- package/build/runtime-esm/routing/cache.js +0 -36
- package/build/runtime-esm/routing/hooks.d.ts +0 -40
- package/build/runtime-esm/routing/hooks.js +0 -53
- package/build/runtime-esm/routing/index.d.ts +0 -3
- package/build/runtime-esm/routing/index.js +0 -6
- package/build/server/index.d.ts +0 -1
- package/build/server-cjs/index.js +0 -28
- package/build/server-cjs/package.json +0 -1
- package/build/server-esm/index.js +0 -4
- package/build/server-esm/package.json +0 -1
- /package/{build/plugin-esm → server}/package.json +0 -0
- /package/{build/runtime-esm → vite}/package.json +0 -0
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { hydrateRoot, createRoot } from 'react-dom/client'
|
|
3
|
+
import type { QueryArtifact, GraphQLVariables } from '$houdini/runtime'
|
|
4
|
+
import type { Cache } from '$houdini/runtime/cache'
|
|
5
|
+
import type { HoudiniClient } from '$houdini/runtime/client'
|
|
6
|
+
import cacheRef from '$houdini/runtime/cache'
|
|
7
|
+
|
|
8
|
+
import { injectComponents } from './componentFields.js'
|
|
9
|
+
import { router_cache, type RouterCache } from './routing/index.js'
|
|
10
|
+
import clientFactory from './client.js'
|
|
11
|
+
|
|
12
|
+
declare global {
|
|
13
|
+
interface Window {
|
|
14
|
+
__houdini__client__?: HoudiniClient
|
|
15
|
+
__houdini__pending_components__?: Record<string, any>
|
|
16
|
+
__houdini__cache__?: Cache
|
|
17
|
+
__houdini__hydration__layer__?: any
|
|
18
|
+
__houdini__initial__cache__?: any
|
|
19
|
+
__houdini__initial__session__?: any
|
|
20
|
+
__houdini__pending_artifacts__?: Record<string, QueryArtifact>
|
|
21
|
+
__houdini__pending_data__?: Record<string, any>
|
|
22
|
+
__houdini__pending_variables__?: Record<string, GraphQLVariables>
|
|
23
|
+
__houdini__nav_caches__?: RouterCache
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function hydrate_page(
|
|
28
|
+
App: React.ComponentType<any>,
|
|
29
|
+
Component: React.ComponentType<any>,
|
|
30
|
+
pageName: string,
|
|
31
|
+
pendingQueries: string[]
|
|
32
|
+
) {
|
|
33
|
+
// set up the client using its internally-managed singleton cache (cacheRef).
|
|
34
|
+
// the client's cachePolicy and queryPlugin are closure-bound to cacheRef at
|
|
35
|
+
// construction time, so we must use that same instance as window.__houdini__cache__
|
|
36
|
+
// rather than creating a second cache and trying to wire them together afterward.
|
|
37
|
+
window.__houdini__client__ ??= clientFactory()
|
|
38
|
+
window.__houdini__cache__ ??= cacheRef
|
|
39
|
+
|
|
40
|
+
// configure the singleton for React component field support
|
|
41
|
+
if (window.__houdini__pending_components__) {
|
|
42
|
+
window.__houdini__client__.componentCache = window.__houdini__pending_components__
|
|
43
|
+
}
|
|
44
|
+
window.__houdini__cache__._internal_unstable.componentCache =
|
|
45
|
+
window.__houdini__client__.componentCache
|
|
46
|
+
window.__houdini__cache__._internal_unstable.createComponent = (
|
|
47
|
+
fn: React.ComponentType<any>,
|
|
48
|
+
props: any
|
|
49
|
+
) => React.createElement(fn, props)
|
|
50
|
+
|
|
51
|
+
window.__houdini__hydration__layer__ ??=
|
|
52
|
+
window.__houdini__cache__._internal_unstable.storage.createLayer()
|
|
53
|
+
|
|
54
|
+
// rehydrate the cache from the server-serialized snapshot
|
|
55
|
+
window.__houdini__cache__?.hydrate(
|
|
56
|
+
window.__houdini__initial__cache__,
|
|
57
|
+
window.__houdini__hydration__layer__
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
// prime the data/artifact caches from anything the server streamed
|
|
61
|
+
const initialData: Record<string, any> = {}
|
|
62
|
+
const initialArtifacts: Record<string, QueryArtifact> = {}
|
|
63
|
+
|
|
64
|
+
for (const [artifactName, artifact] of Object.entries(
|
|
65
|
+
window.__houdini__pending_artifacts__ ?? {}
|
|
66
|
+
)) {
|
|
67
|
+
initialArtifacts[artifactName] = artifact
|
|
68
|
+
|
|
69
|
+
if (window.__houdini__pending_data__?.[artifactName]) {
|
|
70
|
+
const variables = window.__houdini__pending_variables__![artifactName]
|
|
71
|
+
|
|
72
|
+
if ((artifact as any).hasComponents) {
|
|
73
|
+
injectComponents({
|
|
74
|
+
cache: window.__houdini__cache__!,
|
|
75
|
+
selection: (artifact as any).selection,
|
|
76
|
+
data: window.__houdini__pending_data__[artifactName],
|
|
77
|
+
variables,
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const observer = window.__houdini__client__!.observe({
|
|
82
|
+
artifact,
|
|
83
|
+
cache: window.__houdini__cache__,
|
|
84
|
+
initialValue: window.__houdini__cache__!.read({
|
|
85
|
+
selection: (artifact as any).selection,
|
|
86
|
+
variables,
|
|
87
|
+
}).data,
|
|
88
|
+
initialVariables: variables,
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
observer.send({
|
|
92
|
+
setup: true,
|
|
93
|
+
variables,
|
|
94
|
+
session: window.__houdini__initial__session__,
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
initialData[artifactName] = observer
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (!window.__houdini__nav_caches__) {
|
|
102
|
+
window.__houdini__nav_caches__ = router_cache({
|
|
103
|
+
pending_queries: pendingQueries,
|
|
104
|
+
initialData,
|
|
105
|
+
initialVariables: window.__houdini__pending_variables__,
|
|
106
|
+
initialArtifacts,
|
|
107
|
+
components: { [pageName]: Component },
|
|
108
|
+
})
|
|
109
|
+
_flush_pending_artifacts()
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
hydrateRoot(
|
|
113
|
+
document,
|
|
114
|
+
<App
|
|
115
|
+
initialURL={window.location.pathname}
|
|
116
|
+
cache={window.__houdini__cache__}
|
|
117
|
+
session={window.__houdini__initial__session__}
|
|
118
|
+
{...window.__houdini__nav_caches__}
|
|
119
|
+
/>
|
|
120
|
+
)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const _pendingArtifacts: Array<[string, QueryArtifact]> = []
|
|
124
|
+
|
|
125
|
+
export function register_artifact(name: string, artifact: QueryArtifact) {
|
|
126
|
+
const caches = window.__houdini__nav_caches__
|
|
127
|
+
if (!caches?.artifact_cache) {
|
|
128
|
+
_pendingArtifacts.push([name, artifact])
|
|
129
|
+
return
|
|
130
|
+
}
|
|
131
|
+
if (!caches.artifact_cache.has(name)) {
|
|
132
|
+
caches.artifact_cache.set(name, artifact)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function _flush_pending_artifacts() {
|
|
137
|
+
while (_pendingArtifacts.length > 0) {
|
|
138
|
+
const [name, artifact] = _pendingArtifacts.shift()!
|
|
139
|
+
register_artifact(name, artifact)
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function mount_static_app(App: React.ComponentType<any>, manifest: any) {
|
|
144
|
+
const root = createRoot(document.getElementById('app')!)
|
|
145
|
+
|
|
146
|
+
root.render(
|
|
147
|
+
React.createElement(App, {
|
|
148
|
+
initialURL: window.location.pathname,
|
|
149
|
+
cache: cacheRef,
|
|
150
|
+
session: null,
|
|
151
|
+
manifest,
|
|
152
|
+
...router_cache(),
|
|
153
|
+
})
|
|
154
|
+
)
|
|
155
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { GraphQLObject } from 'houdini/runtime'
|
|
2
|
+
import type { Cache } from 'houdini/runtime/cache'
|
|
3
|
+
|
|
4
|
+
import client from './client.js'
|
|
5
|
+
import manifest from './manifest.js'
|
|
6
|
+
import { Router as RouterImpl, type RouterCache, RouterContextProvider } from './routing/index.js'
|
|
7
|
+
|
|
8
|
+
export * from './hooks/index.js'
|
|
9
|
+
export {
|
|
10
|
+
router_cache,
|
|
11
|
+
useCache,
|
|
12
|
+
useSession,
|
|
13
|
+
useLocation,
|
|
14
|
+
useRoute,
|
|
15
|
+
useCurrentVariables,
|
|
16
|
+
notFound,
|
|
17
|
+
unauthorized,
|
|
18
|
+
forbidden,
|
|
19
|
+
httpError,
|
|
20
|
+
redirect,
|
|
21
|
+
isRoutingError,
|
|
22
|
+
isApiError,
|
|
23
|
+
RoutingError,
|
|
24
|
+
RedirectError,
|
|
25
|
+
} from './routing/index.js'
|
|
26
|
+
export * from './Link.js'
|
|
27
|
+
|
|
28
|
+
export function Router({
|
|
29
|
+
cache,
|
|
30
|
+
initialURL,
|
|
31
|
+
artifact_cache,
|
|
32
|
+
component_cache,
|
|
33
|
+
data_cache,
|
|
34
|
+
ssr_signals,
|
|
35
|
+
last_variables,
|
|
36
|
+
session,
|
|
37
|
+
assetPrefix,
|
|
38
|
+
injectToStream,
|
|
39
|
+
}: {
|
|
40
|
+
initialURL: string
|
|
41
|
+
initialVariables: GraphQLObject
|
|
42
|
+
cache: Cache
|
|
43
|
+
session?: App.Session
|
|
44
|
+
assetPrefix: string
|
|
45
|
+
injectToStream?: (chunk: string) => void
|
|
46
|
+
} & RouterCache) {
|
|
47
|
+
return (
|
|
48
|
+
<RouterContextProvider
|
|
49
|
+
client={client()}
|
|
50
|
+
cache={cache}
|
|
51
|
+
artifact_cache={artifact_cache}
|
|
52
|
+
component_cache={component_cache}
|
|
53
|
+
data_cache={data_cache}
|
|
54
|
+
ssr_signals={ssr_signals}
|
|
55
|
+
last_variables={last_variables}
|
|
56
|
+
session={session}
|
|
57
|
+
>
|
|
58
|
+
<RouterImpl
|
|
59
|
+
initialURL={initialURL}
|
|
60
|
+
manifest={manifest}
|
|
61
|
+
assetPrefix={assetPrefix}
|
|
62
|
+
injectToStream={injectToStream}
|
|
63
|
+
/>
|
|
64
|
+
</RouterContextProvider>
|
|
65
|
+
)
|
|
66
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module","main":"./index.tsx"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function resolveHref(
|
|
2
|
+
href: string,
|
|
3
|
+
params: Record<string, string | number | boolean>
|
|
4
|
+
): string {
|
|
5
|
+
// optional [[param]] — strip the whole /[[param]] segment when the value is absent
|
|
6
|
+
href = href.replace(/\/\[\[([^\]]+)\]\]/g, (_, key: string) => {
|
|
7
|
+
const val = params[key]
|
|
8
|
+
return val !== undefined ? '/' + String(val) : ''
|
|
9
|
+
})
|
|
10
|
+
// rest [...slug] — substitute [..slug] with the value (or empty string when absent)
|
|
11
|
+
href = href.replace(/\[\.\.\.([^\]]+)\]/g, (_, key: string) => String(params[key] ?? ''))
|
|
12
|
+
// regular [param]
|
|
13
|
+
return href.replace(/\[([^\]]+)\]/g, (_, key: string) => String(params[key] ?? key))
|
|
14
|
+
}
|