Skip to content

Commit

Permalink
Improve fragmework integration with vite dev server
Browse files Browse the repository at this point in the history
  • Loading branch information
AlecAivazis committed Oct 1, 2023
1 parent 3dfa706 commit 0c81de6
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 36 deletions.
5 changes: 5 additions & 0 deletions .changeset/nice-socks-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'houdini-react': patch
---

Improve integration with vite dev server
2 changes: 1 addition & 1 deletion packages/houdini-plugin-svelte-global-stores/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@
},
"main": "./build/plugin-cjs/index.js",
"types": "./build/plugin/index.d.ts"
}
}
35 changes: 2 additions & 33 deletions packages/houdini-react/src/plugin/vite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -261,37 +261,9 @@ if (window.__houdini__nav_caches__ && window.__houdini__nav_caches__.artifact_ca
)
)) as { default: RouterManifest<React.Component> }

const [match] = find_match(router_manifest, req.url)

if (
!match &&
!internalRoutes(server.houdiniConfig.configFile).find((route) =>
req.url?.startsWith(route)
)
) {
next()
return
}

// its worth loading the project manifest
const project_manifest = await load_manifest({ config: server.houdiniConfig })

// import the schema
let schema: GraphQLSchema | null = null
if (project_manifest.local_schema) {
schema = await loadLocalSchema(server.houdiniConfig)
}

// import the yoga server
let yoga: YogaServer | null = null
if (project_manifest.local_yoga) {
const yogaPath = path.join(server.houdiniConfig.localApiDir, '+yoga')
yoga = (await server.ssrLoadModule(yogaPath)) as YogaServer
}

// load the render factory
const { createServerAdapter } = (await server.ssrLoadModule(
routerConventions.server_adapter_path(server.houdiniConfig)
routerConventions.adapter_config_path(server.houdiniConfig)
)) as { createServerAdapter: any }

const requestHeaders = new Headers()
Expand All @@ -317,17 +289,14 @@ if (window.__houdini__nav_caches__ && window.__houdini__nav_caches__.artifact_ca

// instantiate the handler and invoke it with a mocked response
const result: Response = await createServerAdapter({
schema,
yoga,
production: false,
manifest: router_manifest,
graphqlEndpoint: localApiEndpoint(server.houdiniConfig.configFile),
assetPrefix: '/virtual:houdini',
pipe: res,
documentPremable: `<script type="module" src="/@vite/client" async=""></script>`,
})(request)
if (result && result.status === 404) {
next()
return next()
}
// if we got here but we didn't pipe a response then we have to send the result to the end
if (result && typeof result !== 'boolean') {
Expand Down
2 changes: 1 addition & 1 deletion packages/houdini-svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,4 @@
},
"main": "./build/plugin-cjs/index.js",
"types": "./build/plugin/index.d.ts"
}
}
2 changes: 1 addition & 1 deletion packages/houdini/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,4 @@
"bin": "./build/cmd-esm/index.js",
"main": "./build/lib-cjs/index.js",
"types": "./build/lib/index.d.ts"
}
}

0 comments on commit 0c81de6

Please sign in to comment.