You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
refactor(search): run browser search on comark-content's worker API - #102
comarkdown/comark-content#172 adds a worker API to comark-content. This PR moves comark-docs' browser search onto it. Not meant to be merged: it checks the API in a real app with per-commit previews, alongside nuxt/content#3931, which builds Nuxt Content's worker search on it.
How it fits
comark-content (#172, and #175 stacked on it): the framework-free worker API, serveContentWorker() and connectContentWorker(), plus buildSearchIndex().
Nuxt Content v4 (nuxt/content#3931): wraps it for Nuxt apps: app/content.worker.ts, a generated worker entry, snapshots published in server-only mode, and useNuxtContentWorker() for <UContentSearch>.
Docus, comark-docs, nuxt.com: get client-side full-text search from that layer. Docus can then take comark-docs in as its live mode.
This PR uses comark-content directly, without the Nuxt Content layer, to test the API on its own.
What changed
Worker (app/workers/search.ts, 153 → 29 lines): reads { sha, debug } from its name and passes one instance, built from that commit's snapshot, to serveContentWorker(). The SHA cache, eviction, fetch wrapper and artifact logging are removed.
Composable (app/composables/useSearch.ts): one worker per commit. A switch terminates the current worker and starts the next commit's, passing { sha, debug } through the Worker's name. client.buildSearchIndex() drives the <UContentSearch> status. A search still pending on a terminated worker resolves to no results instead of an error.
Dependencies: nuxt-workers is removed, since a plain new Worker(new URL(...), { type: 'module', name }) is enough. comark-content is installed from https://pkg.pr.new/comark-content@ec7a084, #175's build, which contains #172 too.
Evidence
Before, the worker exported its own RPC, with an SHA cache and eviction, and warmed the index with an empty search:
exportasyncfunctionwarmupSearch(target: SearchTarget): Promise<void>{/* cache, eviction */}exportasyncfunctionsearchContent(query: string,opts?: SearchOptions){/* ... */}// ...awaitcontent.search('')// pulls the snapshot in and builds the FTS index
Production build, in the browser, switching in the page from prod to /blob/96c1546 (a commit from before the "Code highlighting" section) and back. Each step starts a new worker. The local server had just restarted, so it fetched each commit from GitHub on first use:
A read pending when the worker is terminated rejects with "The content worker was terminated." (checked with connectContentWorker() on a MessageChannel), and useSearch() turns that into no results.
Client assets (_nuxt), main → this branch: the search worker chunk goes from 272.8 to 263.1 kB and the entry chunk grows by 1.4 kB.
pnpm lint, pnpm typecheck, pnpm test (211 passed) and pnpm build pass. pack fails because pnpm blocks the pkg.pr.new URL as a dependency of a dependency (ERR_PNPM_EXOTIC_SUBDEP); it passes again once comark-content is a version range.
Notes
A switch starts a new worker, so going back to prod loads and indexes it again (about 115 ms in an earlier run with warm caches). Before, prod stayed loaded in a separate worker.
A missing snapshot (404) still surfaces as "could not initialize", without the status or URL.
The two unused sqlite-wasm helper files (about 245 kB) are still emitted. The separate comark-content PR with sqliteWasmWorker() removes them.
ELI5
comark-docs searches its pages inside a background helper in the browser, so the page doesn't freeze while the search index loads. It used to wire that helper up itself. Now it uses the shared helper from comark-content, which Nuxt Content and Docus will use too, and starts a fresh helper when you switch between versions of the docs.
🤖 Generated with Amp, reviewed by @larbish before opening.
Brotli sizes. Changes under 100 B are left out of the tables. Initial page load counts the JavaScript and CSS a route loads before it renders. Prerendered URLs count the JavaScript and CSS their HTML preloads (module scripts, modulepreload and stylesheets, not prefetch), and the HTML document. Components are the lazy-loaded components the page rendered: its HTML preloads them, but its route's static imports don't reach them. Measured by nuxt-bundle-analyzer for d262529.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
comarkdown/comark-content#172 adds a worker API to comark-content. This PR moves comark-docs' browser search onto it. Not meant to be merged: it checks the API in a real app with per-commit previews, alongside nuxt/content#3931, which builds Nuxt Content's worker search on it.
How it fits
serveContentWorker()andconnectContentWorker(), plusbuildSearchIndex().app/content.worker.ts, a generated worker entry, snapshots published in server-only mode, anduseNuxtContentWorker()for<UContentSearch>.livemode.This PR uses comark-content directly, without the Nuxt Content layer, to test the API on its own.
What changed
app/workers/search.ts, 153 → 29 lines): reads{ sha, debug }from itsnameand passes one instance, built from that commit's snapshot, toserveContentWorker(). The SHA cache, eviction, fetch wrapper and artifact logging are removed.app/composables/useSearch.ts): one worker per commit. A switch terminates the current worker and starts the next commit's, passing{ sha, debug }through the Worker'sname.client.buildSearchIndex()drives the<UContentSearch>status. A search still pending on a terminated worker resolves to no results instead of an error.nuxt-workersis removed, since a plainnew Worker(new URL(...), { type: 'module', name })is enough. comark-content is installed fromhttps://pkg.pr.new/comark-content@ec7a084, #175's build, which contains #172 too.Evidence
Before, the worker exported its own RPC, with an SHA cache and eviction, and warmed the index with an empty search:
After, the whole worker:
And the page side of a switch:
The production build keeps
namein the bundled worker call:Production build, in the browser, switching in the page from prod to
/blob/96c1546(a commit from before the "Code highlighting" section) and back. Each step starts a new worker. The local server had just restarted, so it fetched each commit from GitHub on first use:vitesse/getting-started/configuration#code-highlighting96c1546vitesse96c1546snapshot/blob/96c1546/…vitesseA read pending when the worker is terminated rejects with "The content worker was terminated." (checked with
connectContentWorker()on aMessageChannel), anduseSearch()turns that into no results.Client assets (
_nuxt),main→ this branch: the search worker chunk goes from 272.8 to 263.1 kB and the entry chunk grows by 1.4 kB.pnpm lint,pnpm typecheck,pnpm test(211 passed) andpnpm buildpass.packfails because pnpm blocks thepkg.pr.newURL as a dependency of a dependency (ERR_PNPM_EXOTIC_SUBDEP); it passes again once comark-content is a version range.Notes
sqliteWasmWorker()removes them.ELI5
comark-docs searches its pages inside a background helper in the browser, so the page doesn't freeze while the search index loads. It used to wire that helper up itself. Now it uses the shared helper from comark-content, which Nuxt Content and Docus will use too, and starts a fresh helper when you switch between versions of the docs.
🤖 Generated with Amp, reviewed by @larbish before opening.