Repository navigation
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch had an error being deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
❓ Type of change
📚 Description
Stacked on #3931, which adds the search worker and its
basePathoption. The base branch isfeat/content-worker-search, so this diff only shows the live mode.A site on Nuxt Content v4 serves what its build snapshot holds until the next deploy. comark-docs and nuxt.com serve their content from GitHub at a commit chosen while the site runs, so a push goes live through a webhook with no build. Each of them carries its own code for that. This PR adds it to the module as a
liveoption.live: { ref, maxAge }oncreateNuxtContent():refis a function returning the commit to serve. With severalsourcesit is one function, whose commit pins every source, or one function per source name, so sources can live in different repositories./__nuxt_contentis served at those commits.cache.driverthe app already passes, in one entry, so every server serves the same ones. Without a driver they stay in the server's memory.maxAgeis how many seconds the stored commits are served before the functions are called again. The request that finds them older waits for the functions, and requests arriving meanwhile share the call. WithoutmaxAge, the functions are called on every request.server/content.tsimportscreateNuxtContent()andlastCommit()from@nuxt/content/server, and the v3 server composables move to@nuxt/content/v3/server.@nuxt/content/contentis removed. Once feat!: import createNuxtContent from @nuxt/content/server #3935 is merged intov4andv4into feat: search content in a web worker withapp/content.worker.ts#3931, these changes leave this diff.lastCommit(options): alive.reffunction for aforge()source. It takes the options offorge()and returns the last commit that touchedpathonref, so a push that changes no content file doesn't move the site.resolveContent(content): auto-imported in server code. Returns the content pinned to the commits being served, for server routes such as RSS or a sitemap. A content that isn't live is returned as it is, and so is every content in dev.revalidateContent(content): auto-imported in server code, for a webhook. It calls every function, stores the commits and returns what changed:{ from, to, changed, removed, navigation }for onesource, and one such result per source whose commit moved forsources. It has no purge and no host code. If a function fails, the sources that answered are stored and served, then it throws naming the others.contentnever publishes/__nuxt_content/manifest.jsonor the snapshots, even withapp/content.worker.ts. The app tells the worker where to load a commit's snapshot from withbasePath(feat: search content in a web worker withapp/content.worker.ts#3931).livefails the setup in hybrid mode, withapp/content.ts, with a source that can't be pinned to a commit (fs(),unstorage()), and when a source has no function.liveis not used. The dev server reads the sources as they are, andrevalidateContent()throws, since there is no commit to move.lastCommit()and the comparison of two commits are insrc/runtime/server/commits.ts, which has no Nuxt import, so they can move to comark-content later.Against nuxt/content-v4-temp#42
This PR replaces that draft. Each of its behaviours:
live.refreturns a commit, requests served at itlive.maxAgecontentneedsserver-onlylive.reffailsnuxi prepareresolveContent()server/content.ts, each with abasePathcontenthandleContent()live.snapshot: falsecachestoragecache.driverrevalidateContent()deletes the cached commitlive.refruns in the backgroundliverejected on severalsourcesrevalidateContent()does nothing withoutmaxAgeNew and not in #42:
lastCommit(), therevalidateContent()result, one commit per source, and no static snapshot for a livecontent.Evidence
What a site writes:
Several sources, in one repository or several:
The tests build one fixture,
test/fixtures/live, onforges/fakerepositories that have different files at each commit. Each test starts the build's Vercel function alone, without the static files, with its own forge. A fixture route moves a branch and callsrevalidateContent()as a webhook does, and another reports what was asked of the forge. Each test was seen failing: before its code was written, or with that code broken afterwards.test/live.test.ts, two sources in two repositories, a file-backed cache driver andmaxAge:revalidateContent()returns{ docs: { from: 'd1', to: 'd3', changed: ['/docs', '/docs/new'], removed: ['/docs/old'], navigation: true } }, thennavigation: falsefor a commit that changes one paragraph,{}for a push that changes no file underdocs/, and every document withfrom: nullwhen nothing was stored;maxAgewith no function called, then the next request finds the push;revalidateContent()throw after the other source moved;badgefield, and the module asked nothing of the forge;.vercel/output/statichas no__nuxt_content.test/live-forms.test.ts, three more builds of the fixture:sourcewithout driver normaxAge:revalidateContent()returns one result, and the function is called on every request;test/live-setup.test.ts: the four setup errors.test/live-dev.test.ts: in dev, no function is called,resolveContent()returns the content unpinned, andrevalidateContent()throws.Lint, prepack, typecheck and the full suite (35 files, 150 tests) pass locally, with the CI command
pnpm exec vitest run --maxWorkers 1 --no-file-parallelism.Notes
maxAgeruns out or byrevalidateContent(), not on every request, so an outage of the forge doesn't slow every page.resolveContent()andrevalidateContent()are auto-imported in server code.lastCommit()is imported from@nuxt/content/server, likecreateNuxtContent(): the module also loadsserver/content.tsat build, outside Nitro, where nothing is auto-imported.createNuxtContent()gets two type-only overloads: it returns an instance forsourceand a hub forsources, where its type was their union. Nothing changes at runtime. Without them,const { changed } = await revalidateContent(content)and(await resolveContent(content)).refdon't type-check (TS2322andTS2339withvue-tsc).changedandremovedlist documents. A media file has no source hash to compare.queryCollection()in a server route) still read the content unpinned. A live site reads through/__nuxt_contentorresolveContent().lastCommit()runs against a stub ofcommits.list(), since the fake forge offorges0.3.2 only filters commits by exact file path), a real shared cache such as Vercel Runtime Cache, a build where the function answers but the source can't be read, and media files of a live content.ELI5
Until now a site had to be rebuilt for a text change to show up. With this, the site asks "which version of the content should I show?" while it runs, remembers the answer for a while, and shows that version to everyone. When someone pushes a change, the site is told, moves to the new version in seconds, and says which pages changed so only those are refreshed.
🤖 Generated with Amp, reviewed by @larbish before opening.