Skip to content

fix: reconcile code-defined collection types on cached bootstrap #1014

Open

Description

@bobbwal

Summary

When CACHE_KV contains the versioned bootstrap marker, SonicJS restores the in-memory collection registry but skips
autoRegisterCollectionDocumentTypes().

A newly added code-defined collection therefore appears in the admin UI, but lacks a corresponding document_types record.
Document-backed operations, including slug availability checks, then fail.

Reproduction

Tested at commit 646c75b2 with Node v22.22.0 and npm 10.9.4.

  1. Start an app with CACHE_KV enabled, allowing _sonicjs_bootstrap_v<version> to be created.
  2. Add and register a new code-defined collection without changing SONICJS_VERSION.
  3. Restart the app and create content in the new collection.
  4. Enter a value in its URL Slug field.

The content form loads, but slug validation requests return:

GET /api/content/check-slug?... 400 Bad Request
{"error":"Collection not found or not document-backed"}

The collection is present in the in-memory registry but absent from document_types.

Expected behavior

Cached bootstrap should reconcile registered collections with document_types, so newly added collections work with document-
backed APIs immediately after restart.

Proposed fix

In the kvDone === '1' bootstrap fast path, call:

await autoRegisterCollectionDocumentTypes(c.env.DB)

after hydrating and registering the collection configs.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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