Skip to content

Commit 91ef1b0

Browse files
fix: dynamically import virtual modules (#4252)
1 parent 35d9c60 commit 91ef1b0

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

packages/start-server-core/src/createStartHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export function createStartHandler<TRouter extends AnyRouter>({
106106
const router = createRouter()
107107

108108
// Attach the server-side SSR utils to the client-side router
109-
attachRouterServerSsrUtils(router, getStartManifest())
109+
attachRouterServerSsrUtils(router, await getStartManifest())
110110

111111
// Update the client-side router with the history and context
112112
router.update({

packages/start-server-core/src/router-manifest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { tsrStartManifest } from 'tanstack-start-router-manifest:v'
21
import { rootRouteId } from '@tanstack/router-core'
32

43
declare global {
@@ -12,7 +11,8 @@ declare global {
1211
* special assets that are needed for the client. It does not include relationships
1312
* between routes or any other data that is not needed for the client.
1413
*/
15-
export function getStartManifest() {
14+
export async function getStartManifest() {
15+
const { tsrStartManifest } = await import('tanstack-start-router-manifest:v')
1616
const startManifest = tsrStartManifest()
1717

1818
const rootRoute = (startManifest.routes[rootRouteId] =

packages/start-server-core/src/server-functions-handler.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
11
import { isNotFound } from '@tanstack/router-core'
22
import invariant from 'tiny-invariant'
33
import { startSerializer } from '@tanstack/start-client-core'
4-
// @ts-expect-error
5-
import _serverFnManifest from 'tanstack-start-server-fn-manifest:v'
64
import { getEvent, getResponseStatus } from './h3'
75

8-
const serverFnManifest = _serverFnManifest as Record<
9-
string,
10-
{
11-
functionName: string
12-
extractedFilename: string
13-
importer: () => Promise<any>
14-
}
15-
>
16-
176
function sanitizeBase(base: string | undefined) {
187
if (!base) {
198
throw new Error(
@@ -53,6 +42,19 @@ export const handleServerAction = async ({ request }: { request: Request }) => {
5342
throw new Error('Invalid server action param for serverFnId: ' + serverFnId)
5443
}
5544

45+
const { default: _serverFnManifest } = await import(
46+
// @ts-expect-error
47+
'tanstack-start-server-fn-manifest:v'
48+
)
49+
50+
const serverFnManifest = _serverFnManifest as Record<
51+
string,
52+
{
53+
functionName: string
54+
extractedFilename: string
55+
importer: () => Promise<any>
56+
}
57+
>
5658
const serverFnInfo = serverFnManifest[serverFnId]
5759

5860
if (!serverFnInfo) {

0 commit comments

Comments
 (0)