Skip to content

feat(flame): search provider plugins and @docubook/plugin-search-algolia - #476

Merged
gitfromwildan merged 4 commits into
mainfrom
feat/plugin-search-algolia
Nov 6, 2026
Merged

gitfromwildan merged 4 commits into
mainfrom
feat/plugin-search-algolia

Conversation

@gitfromwildan

Copy link
Copy Markdown
Member

Summary

Flame can now hand its search dialog to a plugin. The first such plugin, @docubook/plugin-search-algolia, lives in the new plugins/ directory: Algolia DocSearch v5 keyword search, plus Ask AI in its own side panel.

Search provider contract (@docubook/flame, minor)

  • A plugin declares a provider on docs pages with a <script type="application/json" id="docubook-search-provider"> block, usually through injectHead. Its module path is relative to the bundle directory.
  • Flame keeps its own search bar, mobile search icon and ⌘ K / Ctrl K. It imports the module the first time a reader hovers, focuses or opens search, and calls open() from the module's default export.
  • With askAi: true, flame adds a Sparkles button beside the sidebar search bar, an Ask AI row in the mobile menu drawer, and ⌘ I / Ctrl I. These call askAi(), a surface separate from the search dialog.
  • A declaration that is missing, invalid or points outside the bundle directory leaves the built-in search in place.
  • DevServerContext gains assetsPath (/assets, or <basePath>/_flame with experimental.pages), so a plugin can serve the files it writes to BuildEndContext.assetsDir during flame dev.
  • SearchProvider, SearchProviderConfig and SearchProviderFactory are exported from @docubook/flame.

@docubook/plugin-search-algolia (private for now)

  • Options (appId, apiKey, indexName, askAi, searchParameters, …) are validated when the build starts. A bad value stops the build with a [plugin:search-algolia] error naming the option.
  • The DocSearch browser build is copied beside flame's bundles and served from the site's own origin, so script-src 'self' needs no change.
  • relativeUrls (default true) opens results on the current site, so search also works in flame dev and on preview deployments.
  • plugins/* joins the pnpm workspace. scripts/check-release-plan.mjs now ignores none entries, which dependents of flame produce.

Docs

  • search/algolia.mdx now documents the plugin: install, where search and Ask AI appear, options, Ask AI, crawler setup and deploy.
  • The crawler config now matches flame's HTML. I checked it against all 28 built docs pages:
    • content is .prose > p, #mdx-content-island p, #mdx-content-island li, #mdx-content-island td. "Last updated" and the "Made with DocuBook" footer were <p> elements inside .prose, so they were indexed on every page. They are now left out. Table cells (788 <td>) were not indexed before and now are. Everything else the old selector caught is still caught.
    • layoutAnchors strips mdx-content-island, the id of the MDX wrapper. main-navbar is no longer in the HTML, so it was removed.
    • renderJavaScript is now false. All content is present in the static HTML, so the crawler needs no browser.
  • plugins.mdx and search/built-in.mdx link to the new plugin.

Release plan

The changeset bumps @docubook/flame by a minor version. The plugin stays private in this PR, for two reasons:

  1. It only works with the flame version that ships this contract. Published now, its workspace:^ peer range would also accept flame 2.4.0, where it silently does nothing.
  2. npm trusted publishing cannot create a new package, so changeset publish would fail on it.

After flame's release:

  1. Set the plugin to 0.1.0 and remove private.
  2. Publish it once by hand with pnpm publish --access public. Use pnpm, not npm, so that workspace:^ becomes ^<flame version>.
  3. Add the trusted publisher for release.yml on npmjs.com.

Later releases go through Changesets.

Verification

  • Flame tests: 845 pass. Plugin tests: 32 pass.
  • tsc and oxlint pass for both packages.
  • scripts/check-release-plan.mjs passes all 6 scenarios.
  • The docs build and the pre-push hook pass.
  • On the built Algolia page, the highlighted lines of the crawler config fall exactly on the 7 values a reader has to replace.
  • The crawler config was checked by parsing the built HTML with jsdom, not by a real Algolia crawl. After deploy, confirm one page in the Crawler's URL Tester.

A plugin declares a search provider on docs pages with a #docubook-search-provider JSON block. Flame keeps its search bar, mobile search icon and Cmd/Ctrl K, imports the provider module on first use and opens its UI. With askAi: true it adds the Ask AI buttons and Cmd/Ctrl I.

DevServerContext gains assetsPath so a plugin can serve the files it writes to BuildEndContext.assetsDir during flame dev.
Algolia DocSearch v5 keyword search in the DocSearch dialog, and Ask AI in the DocSearch Sidepanel, through flame's search provider contract. Options are validated when the build starts. The browser build is copied beside flame's bundles and served from the site's own origin.

The package stays private until its first npm release. plugins/* joins the pnpm workspace, and the release-plan check ignores the 'none' entries that dependents of flame produce.
…nfig to flame's html

The Algolia page now covers the plugin. The crawler config indexes the page description, body paragraphs, list items and table cells inside #mdx-content-island, so 'Last updated' and the footer stay out of the index and table cells become searchable. It strips the mdx-content-island anchor, drops main-navbar (no longer in the HTML) and sets renderJavaScript to false: flame writes every page as static HTML.
@vercel

vercel Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docu Ignored Ignored Preview Nov 6, 2026 1:35am UTC

@gitfromwildan gitfromwildan self-assigned this Nov 6, 2026

@pullfrog pullfrog 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.

ℹ️ No blocking issues. Two rough edges in the plugin's browser module are worth fixing before the first publish.

Reviewed changes

Mode: senior, because the PR touches plugin execution and the search UI on every docs page. I reviewed the whole PR: flame's new search provider contract, the Ask AI buttons in the sidebar, DevServerContext.assetsPath, the new @docubook/plugin-search-algolia package, the workspace and release-plan wiring, and the docs. Verdict: READY WITH MINOR FIXES. No P0 or P1 findings.

  • Search provider contract. search-provider.ts validates the module path before any import happens. It refuses absolute, remote, .. and non-script paths. Failed imports are not cached, and load errors are logged instead of thrown.
  • Search and Sidebar UI. Search picks ProviderSearch when a provider is declared and BuiltinSearch otherwise. The sidebar island is always mounted with createRoot (client.ts), so reading document inside useState cannot cause a hydration mismatch.
  • Dev serving. assetsPath: bundlePath() is set in both server.ts and server.impl.ts. Plugin handleRequest runs before flame's static /assets/ handler, so in dev the plugin serves its own files under the same URL the client builds.
  • Algolia plugin. Options are validated at load time. appId is restricted to an upper-case alphanumeric host label before it goes into the preconnect URL. serializeForScript blocks </script> breakout. Dev file serving rejects encoded traversal. I checked the DocSearch 5.2.0 API this code relies on against the installed package: onReady, keyboardShortcuts keys, isOpen, the ./docsearch subpath, and both surfaces portaling to body. All of it matches.
  • Workspace and release. plugins/* joins the workspace. check-release-plan.mjs now drops none entries. The plugin stays private.
  • Docs. The Algolia guide is rewritten, the crawler config now matches flame's HTML, and plugins.mdx gains a "Search providers" section.

Top priorities:

  1. Stop caching rejected DocSearch chunk imports in the client module.
  2. Version style.css like client.js.

Plugin tests pass locally (32/32).

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using claude-opus-5-5 | 𝕏

- A failed DocSearch or Sidepanel load is no longer cached: retryable() clears it so the next open retries, and the failure is logged instead of left as an unhandled rejection.
- style.css carries the client module's ?v=<version> query, so an upgrade is not served the old theme from a long-lived bundle cache.

@pullfrog pullfrog 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.

✅ No new issues found. Both findings from the previous review are fixed, and their threads are resolved.

Reviewed changes

Mode: senior, re-review of 87469d9, which only touches the plugin's browser module and adds a test. Verdict: READY.

  • Failed loads now retry. loadModal and loadPanel go through the new retryable() helper. It shares one in-flight setup between callers and forgets a rejected one, so the next open() or askAi() loads again. This matches flame's own loader, which doesn't cache failures. The eager prefetch and both call sites end in .catch(logLoadError), so a failed load is logged rather than left as an unhandled rejection.
  • Stylesheet is versioned. The <link> now takes its URL query from import.meta.url, so style.css gets the same ?v=<version> as client.js. Long-lived bundle caches won't serve the old theme after an upgrade.
  • New client test. client.test.ts covers retryable directly. It also checks that the provider logs a failed eager load, recovers on the next open(), and reuses the instance after that. I ran the plugin tests locally on 87469d9: 35 of 35 pass.

Pullfrog  | View workflow run | Using claude-opus-5-5 | 𝕏

@gitfromwildan
gitfromwildan merged commit 93f897f into main Nov 6, 2026
15 checks passed
@gitfromwildan
gitfromwildan deleted the feat/plugin-search-algolia branch November 6, 2026 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant