#5036·nextra

错误: `<Layout>` 始终会抛出"输入无效: 预期为非必选项,但收到 undefined → 在子元素中"

作者: GitHubGW创建于 2026年7月28日更新于 2026年9月17日
标签bug

In nextra-theme-docs/dist/layout.js:

javascript
const Layout = (t0) => {
  ...
  ({ children, ...themeConfig } = t0);
  ...
  const { data, error } = LayoutPropsSchema.safeParse(themeConfig);
  if (error) {
    throw z.prettifyError(error);
  }
  ...

{ children, ...themeConfig } removes the children key from themeConfig entirely. In nextra-theme-docs/dist/schemas.js:

javascript
const LayoutPropsSchema = z.strictObject({
  banner: reactNode.optional().meta({...}),
  children: reactNode,  // <-- required, no `.optional()`
  ...

children has no .optional(). Minimal Zod v4 repro confirming the "missing key" vs "key present but undefined" distinction: