Skip to content

fix(core): don't first-time enable FTS from syncSearchState#595

Merged
ascorbic merged 3 commits intomainfrom
fix/playground-fts-init
Apr 16, 2026
Merged

fix(core): don't first-time enable FTS from syncSearchState#595
ascorbic merged 3 commits intomainfrom
fix/playground-fts-init

Conversation

@ascorbic
Copy link
Copy Markdown
Collaborator

What does this PR do?

Fixes a regression from #465 (0a61ef4) that crashes playground initialization.

syncSearchState was calling enableSearch() when FTS wasn't yet active, which triggered FTS5 operations (drop triggers, create virtual table, etc.) during field creation in the seed. The seed's own enableSearch step at the end handles failures gracefully with a try/catch, but the new createFieldsyncSearchState path didn't — so any FTS failure during field creation killed the entire playground init.

Now syncSearchState only:

  • Rebuilds an already-active FTS index (when searchable fields change)
  • Disables an active FTS index (when search support is removed or no searchable fields remain)

First-time FTS enablement stays with the seed's try-caught enableSearch call and the admin UI's explicit toggle.

Type of change

  • Bug fix

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm lint passes
  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)

AI-generated code disclosure

  • This PR includes AI-generated code

syncSearchState (added in 0a61ef4) called enableSearch() when FTS
wasn't yet active, triggering FTS5 operations during field creation
in the seed. This crashes playground initialization — the seed's
explicit enableSearch step handles failures gracefully with a
try/catch, but the createField code path didn't.

Now syncSearchState only rebuilds an already-active FTS index or
disables one that should be off. First-time enablement stays with
the seed's try-caught enableSearch call.
Copilot AI review requested due to automatic review settings April 16, 2026 06:39
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 16, 2026

🦋 Changeset detected

Latest commit: 04c8b49

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/admin Patch
@emdash-cms/auth Patch
@emdash-cms/blocks Patch
@emdash-cms/gutenberg-to-portable-text Patch
@emdash-cms/x402 Patch
create-emdash Patch
@emdash-cms/plugin-embeds Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Apr 16, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
emdash-playground 04c8b49 Apr 16 2026, 07:26 AM

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 16, 2026

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@595

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@595

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@595

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@595

emdash

npm i https://pkg.pr.new/emdash@595

create-emdash

npm i https://pkg.pr.new/create-emdash@595

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@595

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@595

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@595

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@595

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@595

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@595

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@595

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@595

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@595

commit: 04c8b49

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a regression where SchemaRegistry.syncSearchState() could first-time enable FTS during schema mutations (e.g., field creation during seed), causing unhandled FTS failures to crash playground initialization. This keeps first-time enablement in explicitly try/caught flows (seed + admin toggle) while still maintaining already-enabled indexes.

Changes:

  • Update syncSearchState() to only rebuild an already-enabled FTS index when searchable fields change.
  • Update syncSearchState() to disable FTS only when it is currently active and search support is removed / no searchable fields remain.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +532 to +534
if (wantsSearch && searchableFields.length > 0 && ftsActive) {
await ftsManager.rebuildIndex(collectionSlug, searchableFields, config?.weights);
} else if (ftsActive && (!wantsSearch || searchableFields.length === 0)) {
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

syncSearchState() no longer enables search when supports includes "search" but FTS isn’t active. The docblock above this function (and several existing unit tests) still describe the old "enable or rebuild" behavior, which will now be incorrect and likely cause failing/incorrect tests and developer confusion. Please update the documentation and adjust tests to reflect the new contract (only rebuild/disable; first-time enable handled elsewhere).

Copilot uses AI. Check for mistakes.
Comment on lines +532 to 536
if (wantsSearch && searchableFields.length > 0 && ftsActive) {
await ftsManager.rebuildIndex(collectionSlug, searchableFields, config?.weights);
} else if (ftsActive && (!wantsSearch || searchableFields.length === 0)) {
await ftsManager.disableSearch(collectionSlug);
}
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change intentionally stops first-time FTS enablement in syncSearchState(), but the repository’s current unit tests assert that creating a searchable field or toggling supports: ["search"] auto-creates the FTS table. As-is, this PR will require updating those tests (and ideally adding a test that verifies "no first-time enable" behavior) to keep CI green and to lock in the new intended behavior.

Copilot uses AI. Check for mistakes.
@github-actions github-actions bot added size/M and removed size/S labels Apr 16, 2026
@ascorbic ascorbic enabled auto-merge (squash) April 16, 2026 07:07
@ascorbic ascorbic disabled auto-merge April 16, 2026 07:08
Tests now explicitly call enableSearch() to set up FTS state before
testing rebuild/disable paths, matching the new contract where
syncSearchState never first-time enables FTS.

Atomicity tests updated to mock the operations that actually occur
(rebuildIndex/disableSearch) rather than enableSearch.
@ascorbic ascorbic force-pushed the fix/playground-fts-init branch from 82c0745 to 04c8b49 Compare April 16, 2026 07:24
@ascorbic ascorbic enabled auto-merge (squash) April 16, 2026 07:25
@ascorbic ascorbic merged commit cfd01f3 into main Apr 16, 2026
29 checks passed
@ascorbic ascorbic deleted the fix/playground-fts-init branch April 16, 2026 07:38
@emdashbot emdashbot bot mentioned this pull request Apr 16, 2026
@ascorbic ascorbic mentioned this pull request Apr 16, 2026
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants