Fixes from the reference site: 404 page unlisted, own-origin media, fillGlobal defaults, switcher docs

- sitemap, llms.txt and the site index leave out the page assigned as the 404
  page (unlistedPageIds, exported); it stays when it is also the homepage
- buildImagesConfig: in production with R2_PUBLIC_URL empty, allow the site's
  own /api/media/file/** so next/image no longer answers 400
- fillGlobal: a choice field (select, radio, checkbox, number, date) still at its
  defaultValue counts as empty; text is never overwritten
- docs: LanguageSwitcher renderLabel needs a 'use client' wrapper (i18n.md,
  ipal-site, ipal-setup, api.md)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-10-29 15:29:07 +01:00
co-authored by Claude Opus 5.5
parent d992d131a2
commit 3645e61f7d
19 changed files with 171 additions and 18 deletions
+1 -1
View File
@@ -274,7 +274,7 @@ export type { MediaImageOptions, MediaImageProps, VideoMode, VideoProps } from '
export { getNotificationTexts, NOTIFICATION_FALLBACK, NOTIFICATION_FALLBACK_PL, notificationFallback, resolveFormMessage } from './modules/notifications/index.js'
export type { FormNotificationTexts, NotificationTexts } from './modules/notifications/index.js'
export type { PagesOption, SystemPageRole } from './modules/pages/index.js'
export { ALL_SYSTEM_PAGE_ROLES, getSystemPagePath } from './modules/pages/index.js'
export { ALL_SYSTEM_PAGE_ROLES, getSystemPagePath, unlistedPageIds } from './modules/pages/index.js'
export type { GlobalQueryOptions } from './modules/payload/index.js'
export {
getGlobal,
+1
View File
@@ -2,3 +2,4 @@ export { getSystemPagePath } from './getSystemPagePath.js'
export { buildSystemPagesFields } from './systemPagesFields.js'
export type { PagesOption, SystemPageRole } from './types.js'
export { ALL_SYSTEM_PAGE_ROLES } from './types.js'
export { unlistedPageIds } from './unlistedPages.js'
+21
View File
@@ -0,0 +1,21 @@
/** A relationship value (populated or an id) → its id. */
const idOf = (rel: unknown): number | string | undefined => {
if (typeof rel === 'string' || typeof rel === 'number') {return rel}
if (rel && typeof rel === 'object') {
const id = (rel as { id?: unknown }).id
return typeof id === 'string' || typeof id === 'number' ? id : undefined
}
return undefined
}
/**
* Pages that have no URL of their own, from Site settings → System pages: the page assigned as the
* 404 page renders through not-found.tsx and answers 404 at its own address, so the sitemap, llms.txt
* and the site index leave it out. A 404 page that is also the homepage stays listed.
*/
export function unlistedPageIds(settings: null | Record<string, unknown> | undefined): Set<number | string> {
const ids = new Set<number | string>()
const notFound = idOf(settings?.notFound)
if (notFound !== undefined && notFound !== idOf(settings?.homepage)) {ids.add(notFound)}
return ids
}
+6 -3
View File
@@ -7,8 +7,8 @@ import {
defaultHashField,
defaultUntouchedSeconds,
editedSinceSeed,
hasContent,
isLocalizedValue,
isUnsetValue,
localesOf,
localize,
projectOnto,
@@ -426,9 +426,12 @@ export function createSeeder(payload: BasePayload, options: SeederOptions = {}):
if (!listed(`global:${slug}`)) {return report(notListed(label))}
try {
const target = { global: slug }
const withHash = hasHashField(payload.config.globals.find((g) => g.slug === slug)?.fields as undefined | unknown[])
const global = payload.config.globals.find((g) => g.slug === slug)
const withHash = hasHashField(global?.fields as undefined | unknown[])
const fieldOf = (name: string) => (global?.flattenedFields as { defaultValue?: unknown; name?: string; type?: string }[] | undefined)?.find((f) => f.name === name)
const cur = await readSeedTarget(payload, target, defaultLocale)
const empty = Object.keys(data).filter((k) => !hasContent(cur[k]))
// Empty, or a choice still at its default value (e.g. Theme → light): never text an editor wrote.
const empty = Object.keys(data).filter((k) => isUnsetValue(cur[k], fieldOf(k)))
let keys = empty
let edited: null | string = null
if (update) {
+14
View File
@@ -175,6 +175,20 @@ export async function writeLocales(
}
/** True when a value has content (non-empty text, a number, true, or a nested one). */
/** Field types whose stored value is a choice, not text an editor wrote. */
const CHOICE_TYPES = new Set(['checkbox', 'date', 'number', 'point', 'radio', 'select'])
/**
* A global field nobody has set yet: empty, or — for a choice (select, radio, checkbox, number, date) —
* still holding the field's own `defaultValue`, which Payload stores on the first save of the global.
* Text an editor wrote is never "unset", even when it equals a default.
*/
export function isUnsetValue(value: unknown, field?: { defaultValue?: unknown; type?: string }): boolean {
if (!hasContent(value)) {return true}
if (!field || !CHOICE_TYPES.has(field.type ?? '') || field.defaultValue === undefined || typeof field.defaultValue === 'function') {return false}
return JSON.stringify(value) === JSON.stringify(field.defaultValue)
}
export function hasContent(v: unknown): boolean {
if (typeof v === 'string') {return v.trim() !== ''}
if (typeof v === 'number' || v === true) {return true}
+3
View File
@@ -5,6 +5,7 @@ import type { I18nConfig } from '../i18n/index.js'
import { archiveFieldName } from '../content/index.js'
import { buildLocalizedPath, getLocaleCodes , getLocalizedSlugs } from '../i18n/index.js'
import { unlistedPageIds } from '../pages/unlistedPages.js'
import { buildHreflangAlternates } from './hreflang.js'
/**
@@ -264,6 +265,7 @@ export async function buildSitemapEntries({
}
const entries: SitemapEntry[] = []
const unlisted = unlistedPageIds(settings)
for (const collection of collections) {
// Read every doc once, across locales, so one row yields all its language
@@ -272,6 +274,7 @@ export async function buildSitemapEntries({
// loads every block of every post into memory at once.
for await (const raw of readAll(payload, collection.slug, select)) {
if (!isIndexable(raw)) {continue}
if (collection.slug === pagesSlug && unlisted.has(raw.id)) {continue}
const images = [...new Set(imagesOf(raw).map(absolute).filter((u): u is string => Boolean(u)))]
// Emit a separate <url> for EACH locale. Google's sitemap spec for
+3
View File
@@ -6,6 +6,7 @@ import type { I18nConfig } from '../i18n/index.js'
import { archiveFieldName } from '../content/index.js'
import { buildLocalizedPath, getLocaleCodes, isValidLocale } from '../i18n/index.js'
import { resolveLocalized } from '../i18n/resolveLocalized.js'
import { unlistedPageIds } from '../pages/unlistedPages.js'
/** One public, indexable document in one language. */
export type SiteIndexEntry = {
@@ -154,6 +155,7 @@ export async function collectSiteIndex({
}
const entries: SiteIndexEntry[] = []
const unlisted = unlistedPageIds(settings)
for (const locale of wanted) {
for (const { slug: collection, prefix } of collections) {
// An archive collection without an archive page in this locale has no URLs there.
@@ -170,6 +172,7 @@ export async function collectSiteIndex({
for (const doc of docs) {
if (doc._status && doc._status !== 'published') {continue}
if (doc.noindex || doc.meta?.noindex) {continue}
if (collection === pagesSlug && unlisted.has(doc.id)) {continue}
const title = typeof doc.title === 'string' ? doc.title.trim() : ''
const slug = typeof doc.slug === 'string' ? doc.slug : ''
if (!title || !slug || EXCLUDED_SLUGS.has(slug)) {continue}
+8 -5
View File
@@ -14,9 +14,11 @@ export type ImagesConfig = {
* - remotePatterns for the media domain (R2_PUBLIC_URL) so next/image may
* optimize R2 files — otherwise it refuses them;
* - optimized images cached for 31 days (uploads get new names when replaced);
* - outside production, media served by the app itself (`/api/media/file/**` on
* NEXT_PUBLIC_SERVER_URL — local disk, no R2), including localhost, which
* Next 16 otherwise refuses as a private IP.
* - media served by the app itself (`/api/media/file/**` on NEXT_PUBLIC_SERVER_URL —
* local disk, no R2): always outside production, and in production whenever
* R2_PUBLIC_URL is empty (Payload then gives absolute URLs on the site's own host,
* which next/image refuses with 400 unless they are allowed); outside production
* also localhost, which Next 16 otherwise refuses as a private IP.
*
* import { buildImagesConfig } from '@intecion/ipal-kit'
* export default withPayload({ images: { ...buildImagesConfig(), /* your overrides *\/ } })
@@ -39,7 +41,8 @@ export function buildImagesConfig({
}
for (const host of extraHosts) {remotePatterns.push({ hostname: host, protocol: 'https' })}
let localMedia = false
if (!production && serverUrl && /^https?:\/\//i.test(serverUrl)) {
const r2 = remotePatterns.length > 0
if ((!production || !r2) && serverUrl && /^https?:\/\//i.test(serverUrl)) {
const u = new URL(serverUrl)
remotePatterns.push({
hostname: u.hostname,
@@ -47,7 +50,7 @@ export function buildImagesConfig({
...(u.port ? { port: u.port } : {}),
pathname: '/api/media/file/**',
})
localMedia = /^(?:localhost|127\.|10\.|192\.168\.|\[::1\])/.test(u.hostname)
localMedia = !production && /^(?:localhost|127\.|10\.|192\.168\.|\[::1\])/.test(u.hostname)
}
return {
formats: ['image/avif', 'image/webp'],