Skip to content

[codex] Add LiveSearch route templates#1387

Merged
ascorbic merged 3 commits into
emdash-cms:mainfrom
auggernaut:codex/live-search-routing
Jul 1, 2026
Merged

[codex] Add LiveSearch route templates#1387
ascorbic merged 3 commits into
emdash-cms:mainfrom
auggernaut:codex/live-search-routing

Conversation

@auggernaut

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes LiveSearch result navigation for sites whose public routes do not match the default /{collection}/{slug} shape.

This PR:

  • Adds a routeMap prop so sites can map collection results to public URL templates like /item/:slug.
  • Adds a searchPage prop so pressing Enter without a focused result can navigate to a full search page with ?q= set.
  • Adds style passthrough for the LiveSearch container, matching the existing class passthrough.
  • Returns slug from autocomplete suggestions so suggestMode can use slug-based route templates too.

Closes N/A

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

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)
  • User-visible strings in the admin UI are wrapped for translation (if applicable). Do not include messages.po changes except in translation PRs — a workflow extracts catalogs on merge to main.
  • I have added a changeset (if this PR changes a published package)
  • New features link to an approved Discussion: N/A — bug fix

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: OpenAI GPT-5 Codex

Screenshots / test output

Validation run locally:

  • pnpm --silent lint:json | jq '.diagnostics | length' -> 0
  • pnpm lint
  • pnpm typecheck
  • pnpm --dir packages/core exec vitest run tests/unit/components/live-search-routing.test.ts tests/integration/search/suggest.test.ts
  • pnpm --dir packages/core typecheck
  • pnpm --filter emdash build
  • pnpm format
  • git diff --check

@changeset-bot

changeset-bot Bot commented Jun 8, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5ae4889

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

This PR includes changesets to release 16 packages
Name Type
emdash Patch
@emdash-cms/cloudflare Patch
@emdash-cms/sandbox-workerd Patch
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/do-demo-site Patch
@emdash-cms/do-solo-demo-site 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/auth-atproto 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

@auggernaut

Copy link
Copy Markdown
Contributor Author

/review

@github-actions github-actions Bot added the review/needs-review No maintainer or bot review yet label Jun 8, 2026
@pkg-pr-new

pkg-pr-new Bot commented Jun 8, 2026

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

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

@emdash-cms/auth

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

@emdash-cms/auth-atproto

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

@emdash-cms/blocks

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

@emdash-cms/cloudflare

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

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

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

emdash

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

create-emdash

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

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

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

@emdash-cms/plugin-cli

npm i https://pkg.pr.new/@emdash-cms/plugin-cli@1387

@emdash-cms/plugin-types

npm i https://pkg.pr.new/@emdash-cms/plugin-types@1387

@emdash-cms/registry-client

npm i https://pkg.pr.new/@emdash-cms/registry-client@1387

@emdash-cms/registry-lexicons

npm i https://pkg.pr.new/@emdash-cms/registry-lexicons@1387

@emdash-cms/sandbox-workerd

npm i https://pkg.pr.new/@emdash-cms/sandbox-workerd@1387

@emdash-cms/x402

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

@emdash-cms/plugin-ai-moderation

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

@emdash-cms/plugin-atproto

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

@emdash-cms/plugin-audit-log

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

@emdash-cms/plugin-color

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

@emdash-cms/plugin-embeds

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

@emdash-cms/plugin-field-kit

npm i https://pkg.pr.new/@emdash-cms/plugin-field-kit@1387

@emdash-cms/plugin-forms

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

@emdash-cms/plugin-webhook-notifier

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

commit: 5ae4889

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This PR fixes a real gap: LiveSearch previously hardcoded /{collection}/{slug} for all result links, which breaks sites whose public routes differ. The approach—extracting URL generation into buildLiveSearchResultUrl, adding routeMap/searchPage/style props, and returning slug from the suggestion query so both modes can use slug-based templates—is clean and matches existing full-search behavior.

I found two implementation bugs and one inconsistency:

  1. replaceAll replacement-string interpolation in buildLiveSearchResultUrl: String.prototype.replaceAll treats $ sequences ($$, $&, $', $`, $n) as special patterns in the replacement string. If a result id, slug, or collection contains $, the generated URL is corrupted.
  2. Missing .js extension on the internal ESM import inside the <script> tag (AGENTS.md convention: "Internal imports use .js extensions").
  3. Suggestion links omit data-slug even though suggestions now carry slug, creating an inconsistency with renderResults.

The SQL addition (c.slug in getSuggestions) is safe and consistent with the existing full-search query. The changeset and targeted tests are present. No locale-filtering or authorization regressions.

@auggernaut

Copy link
Copy Markdown
Contributor Author

/review

@github-actions github-actions Bot added review/needs-rereview Author pushed changes since the last review and removed review/needs-review No maintainer or bot review yet labels Jun 8, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR has been inactive for 14 days. It will be closed automatically in 7 days if there is no further activity.

If you're still working on this, please push an update or leave a comment.

@github-actions github-actions Bot added stale and removed stale labels Jun 23, 2026
@ascorbic ascorbic added the bot:review Trigger an emdashbot code review on this PR label Jul 1, 2026

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This re-review confirms the PR is now clean.

The approach is still sound: extracting URL generation into buildLiveSearchResultUrl, adding routeMap/searchPage/style props, and returning slug from the suggestions query so both full-search and suggest mode can use slug-based templates correctly fits EmDash's architecture.

All three findings from the previous review are addressed:

  1. replaceAll replacement-string interpolation — fixed by using template.split(token).join(value) in buildLiveSearchResultUrl, which treats $ sequences as literal text.
  2. Missing .js extension on the internal ESM import — fixed; the <script> block now imports from "./live-search-routing.js".
  3. Suggestion links omitting data-slug — fixed; renderSuggestions now sets link.dataset.slug = suggestion.slug ?? "", consistent with renderResults.

I re-read the changed files and searched the package exports / sibling components. No new blocking issues, security gaps, or AGENTS.md convention violations were introduced. The targeted unit test for buildLiveSearchResultUrl now covers dollar-sign edge cases, the integration test verifies slug is returned from getSuggestions, and the changeset is present.

Verdict: approve.

@ascorbic ascorbic enabled auto-merge (squash) July 1, 2026 17:19
@ascorbic ascorbic merged commit 46ef945 into emdash-cms:main Jul 1, 2026
45 checks passed
@emdashbot emdashbot Bot mentioned this pull request Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core bot:review Trigger an emdashbot code review on this PR review/needs-rereview Author pushed changes since the last review size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants