Theme switcher, table of contents, missing-page redirect, form placeholders and time field; audit and revalidate fixes

- buildRevalidateHook skips outside Next (no NEXT_RUNTIME) and with context.disableRevalidate
- BuilderForm focuses only on a real step change (no scroll to the form on remount)
- mediaImageProps: placeholder colour only for JPEG (placeholderColor); hook stores no colour for transparent images
- buildLinkField: interface name per shape (CmsLink, CmsLinkPlain, CmsLinkNoLabel) + interfaceName option
- Cookie Settings: buttons.save -> buttons.savePreferences (Mongoose reserved name)
- ThemeScript, ThemeSwitcher, useTheme; Site Settings defaultTheme 'system' + themeToggleLabel; Turnstile follows page theme
- extractHeadings, RenderRichText headingIds, TableOfContents, buildTableOfContentsField
- createPageRoute onMissing: 'redirectHome'
- Form builder: localized placeholder on text/email/textarea/number, new time field
- ipal-audit: no false positive for object keys between JSX elements; /md route not reported as dynamic

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-10-19 21:32:40 +02:00
co-authored by Claude Opus 5.5
parent 23e033d7d7
commit faa4ad679c
55 changed files with 1298 additions and 58 deletions
+17 -2
View File
@@ -20,6 +20,17 @@ type BuildRevalidateHookArgs = {
type DocWithSlug = { slug?: unknown }
/**
* Revalidation only makes sense inside a running Next server. Outside it
* (`payload run`, seeds via tsx, migrations) next/cache throws "Invariant: static
* generation store missing". `context.disableRevalidate` (Payload templates'
* convention) skips it on purpose, e.g. in a bulk import.
*/
function shouldRevalidate(context: unknown): boolean {
if (!process.env.NEXT_RUNTIME) {return false}
return !(context && typeof context === 'object' && (context as { disableRevalidate?: unknown }).disableRevalidate)
}
/** Resolve a doc's path in one locale (root for home). Null if no slug there. */
function pathForLocale(
doc: DocWithSlug,
@@ -47,6 +58,8 @@ function pathForLocale(
* Handles every locale, the root (home), AND a changed slug (revalidates both the
* old and new path so neither goes stale). revalidatePath is injected — the
* plugin never imports next/cache (safe under generate:importmap / plain Node).
* Outside a Next server (no NEXT_RUNTIME: `payload run`, seeds, migrations) and
* with `context: { disableRevalidate: true }` the hooks do nothing.
*
* // in your Media/Pages collection config, from a project file that CAN import next/cache:
* import { revalidatePath } from 'next/cache'
@@ -64,7 +77,8 @@ export function buildRevalidateHook({
} {
const locales = getLocaleCodes(config)
const afterChange: CollectionAfterChangeHook = ({ doc, previousDoc }) => {
const afterChange: CollectionAfterChangeHook = ({ context, doc, previousDoc }) => {
if (!shouldRevalidate(context)) {return doc}
const seen = new Set<string>()
for (const locale of locales) {
// New path.
@@ -85,7 +99,8 @@ export function buildRevalidateHook({
return doc
}
const afterDelete: CollectionAfterDeleteHook = ({ doc }) => {
const afterDelete: CollectionAfterDeleteHook = ({ context, doc }) => {
if (!shouldRevalidate(context)) {return doc}
const seen = new Set<string>()
for (const locale of locales) {
const path = pathForLocale(doc as DocWithSlug, locale, config, homeSlug)