Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Client navigation to a server route without a `search` schema throws: args carry `search: undefined`, which JSON arguments reject

已关闭
#615 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
65/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃

调研方向

Look at src/serverRouteShared.ts to see how serverRouteArgs always returns search: undefined. Understand the isJSONSafe check in @solidjs/web that rejects undefined. The fix likely involves modifying the router to omit the search key when no schema exists, or adjusting the serialization logic. Test by reproducing the bug with the provided example and verifying client navigation works after changes.

由索引模型根据 Issue 内容生成。

描述

Describe the bug

serverRouteArgs (src/serverRouteShared.ts) always returns { params, search }, and search is undefined when the route declares no search schema. On the client, @solidjs/web sends server function arguments as plain JSON by default. Its isJSONSafe check rejects undefined anywhere in the arguments, so the call throws before any request is made:

Server function arguments are sent as JSON by default and these arguments are not JSON-serializable. Call enableRichArguments() (from "@solidjs/web/server-functions/rich-args") once at startup ...

The route shows the error boundary instead of the page. Server rendering is not affected, because the server calls the function directly, so the first page load works and only client navigation fails. This covers every serverRouteComponent route and every file-system server page that has no search schema, which is the common case.

Your Example Website or App

The code below. I ran it as-is in a Vite start-mode app whose src/app.tsx renders <Router> inside <Loading>.

Steps to Reproduce the Bug or Issue

With @solidjs/[email protected], @solidjs/[email protected] and @solidjs/[email protected] (start: {}, ssr: true, serverFunctions: { components: true }):

import { createRouter, defineRoute, query, serverRouteComponent } from "@solidjs/router";

const home = async () => {
  "use server";
  return () => <a href="/about">About</a>;
};
const about = async () => {
  "use server";
  return () => <p>About</p>;
};

export const Router = createRouter({
  routes: [
    defineRoute({ path: "/", component: serverRouteComponent(query(home, "home")) }),
    defineRoute({ path: "/about", component: serverRouteComponent(query(about, "about")) })
  ]
});
  1. Load /. It renders.
  2. Click the "About" link.
  3. The client throws the error above, and no /_server/data/... request is sent.

Calling enableRichArguments() at startup makes the navigation work, which confirms search: undefined is the only non-JSON value in the arguments.

Expected behavior

Navigating to a server route without a search schema should work with the default JSON argument encoding. The router could leave the search key out when there is no schema. A missing key and an explicit undefined look the same to the server function's destructuring, and the query key only needs the args to be stable. Alternatively, @solidjs/web's isJSONSafe could skip undefined object properties the way JSON.stringify does. The router seems like the smaller fix, since apps shouldn't need rich arguments just to use server routes.

Screenshots or Videos

None.

Platform
Additional context

Using enableRichArguments() as a workaround currently runs into a separate @solidjs/web packaging bug in Vite builds (the rich-args import does not resolve under rolldown), so apps need a resolve alias as well.

主要语言
TypeScript
星标
1.3k
派生
180
平均合并
1 天 7 小时
30 天内合并 PR
21

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

solidjs/solid-router 的其他 Issue

查看 solidjs/solid-router 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。