Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createTRPCHandle conflict with sveltekit prerender #133

Open
J4gQBqqR opened this issue Jan 12, 2025 · 0 comments
Open

createTRPCHandle conflict with sveltekit prerender #133

J4gQBqqR opened this issue Jan 12, 2025 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@J4gQBqqR
Copy link

Describe the bug
In the implementation of createTRPCHandle, the url.searchParams is used. This usage conflict with the prerender feature of sveltekit.

export function createTRPCHandle({ router, url = '/trpc', createContext, responseMeta, onError }) {
    return async ({ event, resolve }) => {
        if (event.url.pathname.startsWith(url + '/')) {
            const request = event.request;
            const req = {
                method: request.method,
                headers: request.headers,
                query: event.url.searchParams,
                body: await request.text()
            };
    ............

To Reproduce
Steps to reproduce the behavior:
export const prerender = true; will result in the following error when building the project:

Error: Cannot access url.searchParams on a page with prerendering enabled
    at URL.get (file:///home/yuwei/osm/website/.svelte-kit/output/server/chunks/exports.js:1:1412)
    at Object.handle (file:///home/yuwei/osm/website/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]_@sveltejs+vite-plugin_oocbzuje2cxipc7p2nujgvwxb4/node_modules/trpc-sveltekit/dist/server.js:17:34)
    at It (file:///home/yuwei/osm/website/.svelte-kit/output/server/index.js:66:12690)
    at runNextTicks (node:internal/process/task_queues:65:5)
    at listOnTimeout (node:internal/timers:575:9)
    at process.processTimers (node:internal/timers:549:7)
    at async fetch (file:///home/yuwei/osm/website/.svelte-kit/output/server/index.js:66:8409)
node:internal/event_target:1101
  process.nextTick(() => { throw err; });
                           ^

TRPCClientError: Unable to transform response from server
    at TRPCClientError.from (file:///home/yuwei/osm/website/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@trpc/client/dist/TRPCClientError-38f9a32a.mjs:38:16)
    at file:///home/yuwei/osm/website/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@trpc/client/dist/httpBatchLink-d0f9eac9.mjs:200:56
    at runNextTicks (node:internal/process/task_queues:65:5)
    at listOnTimeout (node:internal/timers:575:9)
    at process.processTimers (node:internal/timers:549:7)
Emitted 'error' event on Worker instance at:
    at [kOnErrorMessage] (node:internal/worker:326:10)
    at [kOnMessage] (node:internal/worker:337:37)
    at MessagePort.<anonymous> (node:internal/worker:232:57)
    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:827:20)
    at MessagePort.<anonymous> (node:internal/per_context/messageport:23:28) {
  [cause]: Error: Unable to transform response from server
      at transformResult (file:///home/yuwei/osm/website/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@trpc/client/dist/transformResult-ace864b8.mjs:46:15)
      at file:///home/yuwei/osm/website/node_modules/.pnpm/@[email protected]_@[email protected]/node_modules/@trpc/client/dist/httpBatchLink-d0f9eac9.mjs:187:45
      at runNextTicks (node:internal/process/task_queues:65:5)
      at listOnTimeout (node:internal/timers:575:9)
      at process.processTimers (node:internal/timers:549:7)
}

Node.js v23.4.0
 ELIFECYCLE  Command failed with exit code 1

Expected behavior
trpc should work together with sveltekit prerender feature.

@J4gQBqqR J4gQBqqR added the bug Something isn't working label Jan 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants