Repository navigation
Global blocks: translation, preview, depth and search (gaps from #210) - #212
Conversation
Follow-up to the global blocks correctness fixes (#211). Addresses the remaining gaps from #210, parts 1, 2, 4, 5 and 6: - Wire `globalBlock` into the translator, scheduling and comments plugins so a shared block can be AI-translated, scheduled and commented on. - Add a standalone preview route (`/[locale]/preview/global-block/[id]`) and wire `admin.livePreview` / `admin.preview`, so an editor can see a global block before publishing it to every page that embeds it. - Re-populate the slot reference at the page render depth so a global block's inner relationships get the same population as page blocks. - Index `rawHtml` block text for semantic search, stripping tags and dropping `<script>` / `<style>` content. - Re-index every locale on page and global block saves, because locale fallback can change the rendered text of locales other than the edited one. Both re-index paths now extract at the same depth so neither overwrites the other's embedding with less text. Part 3 (a "make this block global" admin action) is intentionally left for a dedicated follow-up — it is an interactive admin-form mutation that needs live iteration in the panel to get right. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0166RzePhuVEPA8r65QFJV5J
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Resolve overlap with the new upstream commit (shared `isPublishedGlobalBlock` / `collectGlobalBlockIds`, the draft-only-save skip, and the resolveGlobalBlocks refactor): - Slot renderer keeps the GlobalBlockRenderer re-fetch (depth parity) but now gates on the shared `isPublishedGlobalBlock`. - `extractPageText` indexes the published block's first *visible* inner block. - `resolveGlobalBlocks` keeps the upstream refactor plus the `depth` param. - The global-block revalidation hook keeps upstream's publish-change guard and uses `PAGE_EMBEDDING_DEPTH` when loading pages for re-indexing. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0166RzePhuVEPA8r65QFJV5J
|
Consolidated into #211 (commit 8e611dc), which is why GitHub marks this as merged. Kept: plugins, preview route, render depth, rawHtml search, page-save re-index in every locale. Changed: global block text stays out of page search vectors, so the global block re-index path and |
|
🎉 This PR is included in version 1.1.1 🎉 The release is available on npm package (@latest dist-tag) Your semantic-release bot 📦🚀 |
|
🎉 This PR is included in version 0.18.1 🎉 The release is available on npm package (@latest dist-tag) Your semantic-release bot 📦🚀 |
|
🎉 This PR is included in version 1.4.0 🎉 The release is available on npm package (@latest dist-tag) Your semantic-release bot 📦🚀 |
Addresses #210 — the remaining global-blocks gaps (parts 1, 2, 4, 5, 6).
What changed
1. Translation, scheduled publishing and comments for global blocks (
src/lib/plugins/index.ts)globalBlockis now in thetranslatorPlugin,schedulePublicationPluginandcommentsPlugincollection lists, so a shared block can be AI-translated, scheduled, and commented on — not just the pages that embed it. No migration: scheduling rides on the existingpayload_jobscollection, comments injects only admin components, and translatorprovenanceis not enabled.2. Standalone preview for a global block (
GlobalBlockconfig + new route)New route
/[locale]/preview/global-block/[id]renders the single block, wired toadmin.livePreview/admin.preview. The locale prefix follows theas-neededrouting policy (default locale unprefixed). Lets an editor see a block before publishing it to every page that embeds it.4. Inner relationships populated at full depth (
GlobalBlockRenderer)The page query spends one
depthlevel on the slot relationship, so a global block's inner relationships were populated one level shallower than the same block placed directly on a page. The renderer now re-fetches the referenced block at the page render depth (PAGE_RENDER_DEPTH = 3), respecting draft + locale. Extracted into a sharedGlobalBlockRendererused by both the slot block and the preview route.5.
rawHtmlindexed for semantic search (RawHtml/extractText.ts+extractPageText)New
rawHtmlcase strips tags and drops<script>/<style>content (the opening-tag match tolerates>inside quoted attributes) before indexing.6. Re-index every locale on page and global-block saves (
indexEmbedding+revalidatePagesUsingGlobalBlock)Decision for the open question in part 6: yes, cover every locale, for both page saves and global-block saves — locale fallback means an
enedit changes the rendered (and therefore indexable) text ofespages that fall back toen. Both re-index paths now extract at the same depth (PAGE_EMBEDDING_DEPTH = 2, threaded intoresolveGlobalBlocks) so neither overwrites the other's embedding with less text, and so a block that reads a relationship (e.g.testimonialsList) is indexed.Not included — part 3 ("make this block global" action)
Left for a dedicated follow-up. It's an interactive admin-form mutation (create a
globalBlockfrom a page block's data, then swap the block for aglobalSectionSlotvia Payload's formreplaceFieldRowAPI) that needs live iteration in the admin panel to get right — not something to land unverified in a batch PR. This PR does not close #210 for that reason.How it was verified
bun run check-types— passes across the whole repo.bun run lint(ultracite check) — 0 warnings / 0 errors on changed files.bun run build— compiles successfully (✓ Compiled successfully); the build only stops at "Collecting page data" because this sandbox can't reach the Neon database. CI / the Vercel preview run the full build + migrations./code-reviewand/simplifyon the diff; findings addressed (locale-prefix in the preview path, consistent embedding depth across re-index paths, hidden-block parity between render and index, hardened script/style stripping).>inside a script attribute) — script/style content fully dropped.Design note for the reviewer (part 4)
The slot renderer re-fetches the referenced block at
PAGE_RENDER_DEPTHso inner relationships reach parity with page blocks. An alternative is to resolve slots in the data layer (getPageBySlugQuery→resolveGlobalBlockswith adraftoption), which would batch the fetch and ride the page cache. I kept the renderer-side fetch here becauseresolveGlobalBlocksis request-scoped (req.payload) while the render DAL is payload-client/cache-scoped, so unifying would mean reworking that shared resolver and its draft handling — more surface than I could runtime-verify without a DB. Happy to switch to the data-layer approach if you'd prefer it.Please test manually (needs the admin + a DB)
endefault-unprefixed andesprefixed URLs).rawHtmltext and global-block content.Generated by Claude Code