Skip to content

previewTemplate serializes internal info collection's source: undefined as source: [] #3767

@humanbird

Description

@humanbird

Environment

  • OS: macOS 15.4 (Darwin 25.4.0 arm64)
  • Node: v24.13.0
  • Nuxt: 4.4.2
  • @nuxt/content: 3.12.0
  • nuxt-studio: 1.6.0

Version

3.12.0

Reproduction

The bug is in the compiled source at dist/module.mjs and can be verified by inspecting the /__preview.json endpoint output. Steps:

  1. Create a Nuxt 4 project with @nuxt/content v3 and nuxt-studio
  2. Define any content collections in content.config.ts
  3. Deploy with SSR and navigate to /__preview.json
  4. Observe that the info collection has "source": [] instead of being excluded or having source omitted

Description

The internal info collection created by resolveCollections() has source: void 0 (line 2405 of dist/module.mjs):

collections.info = {
  type: "data",
  source: void 0,
  schema: infoStandardSchema,
  // ...
};

The previewTemplate() function (line 1701) serializes this into source: []:

source: collection.source?.filter((source) => source.repository ? void 0 : collection.source) || [],

Since undefined?.filter(...) evaluates to undefined, the || [] fallback kicks in, producing source: [] in the serialized output.

This causes downstream crashes in nuxt-studio, which iterates all collections and accesses source[0].include / source[0].prefix without guarding against empty arrays — resulting in TypeError: Cannot read properties of undefined (reading 'include').

See also: nuxt-content/nuxt-studio#425

Suggested fix

Either exclude collections without source from the preview payload:

// In previewTemplate, skip the info collection
if (!collection.source) return acc;

Or use ?? instead of || to preserve the distinction:

source: collection.source?.filter((source) => source.repository ? void 0 : collection.source) ?? undefined,

(With ?? undefined, JSON.stringify will omit the key entirely.)

I'm happy to submit a PR if you'd prefer one approach over the other.

Additional context

The nuxt-studio side also lacks null guards (tracked in nuxt-content/nuxt-studio#425), but the root cause is the serialization here — source: void 0 should not become source: [] in the preview payload.

Logs

TypeError: Cannot read properties of undefined (reading 'include')
    at parseSourceBase (source.js)
    at Array.map
    at async Object.list
    at async Object.load (main-CUjoLU7k.js)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions