Skip to content

createTRPCHandle conflict with sveltekit prerender  #133

@ghost

Description

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/trpc-sveltekit@3.6.2_@sveltejs+adapter-node@5.2.11_@sveltejs+kit@2.15.2_@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/@trpc+client@10.45.2_@trpc+server@10.45.2/node_modules/@trpc/client/dist/TRPCClientError-38f9a32a.mjs:38:16)
    at file:///home/yuwei/osm/website/node_modules/.pnpm/@trpc+client@10.45.2_@trpc+server@10.45.2/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/@trpc+client@10.45.2_@trpc+server@10.45.2/node_modules/@trpc/client/dist/transformResult-ace864b8.mjs:46:15)
      at file:///home/yuwei/osm/website/node_modules/.pnpm/@trpc+client@10.45.2_@trpc+server@10.45.2/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.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions