1.18.0 performance items: tests, the reference budget gate tightened (JS 195 kB, 404 without its exception, TTL check), docs (performance.md, AGENT.md, iapl-performance, module pages, api.md), changelog: what changes for an existing site

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-12-01 15:54:15 +01:00
co-authored by Claude Opus 5.5
parent d628839235
commit f0127ac1b8
35 changed files with 1154 additions and 288 deletions
+4 -2
View File
@@ -1,7 +1,7 @@
import type { ReactElement, ReactNode } from 'react'
import { Children, cloneElement, createElement as h, isValidElement } from 'react'
import { renderToStaticMarkup } from 'react-dom/server'
import { prerender } from 'react-dom/static'
import { describe, expect, test, vi } from 'vitest'
import type { BlockContent, BlockRegistryOptions } from '../src/exports/blocks-rsc.js'
@@ -34,7 +34,9 @@ async function expand(node: ReactNode): Promise<ReactNode> {
return cloneElement(el, undefined, ...kids)
}
const render = async (node: ReactNode) => renderToStaticMarkup(h('div', null, (await expand(node)) as ReactNode))
// prerender waits for every lazy part, like Next's server render: the form's code is lazy since 1.18.0
const render = async (node: ReactNode) =>
(await new Response((await prerender(h('div', null, (await expand(node)) as ReactNode))).prelude).text()).replace(/<!--(?: |\$\??|\/\$)-->/g, '') // hydration markers out: the markup as before
const image = (alt = 'Photo') => ({ id: 1, alt, filename: 'a.jpg', height: 600, mimeType: 'image/jpeg', url: '/media/a.jpg', width: 900 })
const link = (label: string) => ({ type: 'internal' as const, appearance: 'primary', label, page: { id: 2, slug: 'kontakt' } })
+4 -4
View File
@@ -1,5 +1,6 @@
import { createElement, isValidElement } from 'react'
import { renderToStaticMarkup } from 'react-dom/server'
import { prerender } from 'react-dom/static'
import { describe, expect, test, vi } from 'vitest'
import type { BuilderField, BuilderFormDoc } from '../src/modules/forms/builderTypes.js'
@@ -160,11 +161,10 @@ describe('page values (values prop) and prepareBuilderForm', () => {
expect(html).not.toContain('unknown')
})
test('RenderForm passes values through', () => {
test('RenderForm passes values through (the lazy form renders in full on the server)', async () => {
const action = async () => ({ message: 'ok', success: true })
const html = renderToStaticMarkup(
createElement(RenderForm, { action, form: withSubject, locale: 'pl', texts, values: { subject: 'Broszki' } }),
)
const { prelude } = await prerender(createElement(RenderForm, { action, form: withSubject, locale: 'pl', texts, values: { subject: 'Broszki' } }))
const html = await new Response(prelude).text()
expect(html).toContain('Broszki')
})
+2 -2
View File
@@ -420,8 +420,8 @@ describe('consent log: on by default, fails soft without its table', () => {
const lines = logger.error.mock.calls.map((c) => String(c[0])).filter((m) => m.includes('consent-records table does not exist'))
expect(lines.length).toBeLessThanOrEqual(1)
expect(payload.create).toHaveBeenCalledTimes(2)
// the body's gpc never reaches the record (the shape is unchanged)
expect(Object.keys((payload.create.mock.calls[0] as unknown as [{ data: object }])[0].data).sort()).toEqual(['choices', 'consentId', 'version'])
// the body's gpc never reaches the record; iaplTtlFrom is the date a MongoDB TTL index counts from (1.18.0)
expect(Object.keys((payload.create.mock.calls[0] as unknown as [{ data: object }])[0].data).sort()).toEqual(['choices', 'consentId', 'iaplTtlFrom', 'version'])
})
describe('limits: body size and version', () => {
+11 -11
View File
@@ -91,7 +91,7 @@ describe('TTL indexes (item 10)', () => {
return {}
},
}
const payload = { db: { collections: { 'consent-records': { collection: coll } }, connection: { db: { command: async (c: object) => void calls.push(`collMod ${JSON.stringify(c)}`) } }, name: 'mongoose' } }
const payload = { db: { name: 'mongoose', collections: { 'consent-records': { collection: coll } }, connection: { db: { command: async (c: object) => void calls.push(`collMod ${JSON.stringify(c)}`) } } } }
return { calls, payload: payload as never }
}
@@ -99,18 +99,18 @@ describe('TTL indexes (item 10)', () => {
const { calls, payload } = fake([{ name: '_id_' }, { name: 'createdAt_1' }])
expect(await syncTtlIndex(payload, 'consent-records', { days: 1095, enabled: true, from: 'createdAt' })).toBe('created')
expect(calls).toEqual([
`backfill {"${TTL_FIELD}":{"$exists":false},"createdAt":{"$type":"date"}} [{"$set":{"${TTL_FIELD}":"$createdAt"}}]`,
`backfill {"createdAt":{"$type":"date"},"${TTL_FIELD}":{"$exists":false}} [{"$set":{"${TTL_FIELD}":"$createdAt"}}]`,
`create {"${TTL_FIELD}":1} ${1095 * 86_400}`,
])
})
test('a changed retention moves the index (collMod); the same one does nothing; off drops it', async () => {
const changed = fake([{ expireAfterSeconds: 90 * 86_400, name: TTL_INDEX }])
const changed = fake([{ name: TTL_INDEX, expireAfterSeconds: 90 * 86_400 }])
expect(await syncTtlIndex(changed.payload, 'consent-records', { days: 30, enabled: true, from: 'lastAt' })).toBe('updated')
expect(changed.calls.at(-1)).toBe(`collMod {"collMod":"consent-records","index":{"expireAfterSeconds":${30 * 86_400},"name":"${TTL_INDEX}"}}`)
const same = fake([{ expireAfterSeconds: 30 * 86_400, name: TTL_INDEX }])
expect(changed.calls.at(-1)).toBe(`collMod {"collMod":"consent-records","index":{"name":"${TTL_INDEX}","expireAfterSeconds":${30 * 86_400}}}`)
const same = fake([{ name: TTL_INDEX, expireAfterSeconds: 30 * 86_400 }])
expect(await syncTtlIndex(same.payload, 'consent-records', { days: 30, enabled: true, from: 'lastAt' })).toBe('none')
const off = fake([{ expireAfterSeconds: 30 * 86_400, name: TTL_INDEX }])
const off = fake([{ name: TTL_INDEX, expireAfterSeconds: 30 * 86_400 }])
expect(await syncTtlIndex(off.payload, 'consent-records', { days: 30, enabled: false, from: 'lastAt' })).toBe('dropped')
expect(off.calls).toEqual([`drop ${TTL_INDEX}`])
})
@@ -127,7 +127,7 @@ describe('versions (item 13)', () => {
expect(withVersionLimit({ slug: 'site-integrations', versions: true }, 'global').versions).toEqual({ max: 20 })
expect(withVersionLimit({ slug: 'forms', versions: { drafts: true } }, 'collection').versions).toEqual({ drafts: true, maxPerDoc: 20 })
expect(withVersionLimit({ slug: 'forms', versions: { maxPerDoc: 0 } }, 'collection').versions).toEqual({ maxPerDoc: 0 }) // the project's own (unlimited) wins
expect(withVersionLimit({ slug: 'forms' }, 'collection').versions).toBeUndefined()
expect(withVersionLimit({ slug: 'forms' } as { slug: string; versions?: unknown }, 'collection').versions).toBeUndefined()
})
test('doctor hint for a project that turns versions on without a limit', async () => {
@@ -160,10 +160,10 @@ describe('unused media in the panel (item 12)', () => {
find: async ({ collection }: { collection: string }) => ({ docs: docs[collection] ?? [] }),
findGlobal: async () => ({}),
})
const editor = { collection: 'users', id: 1, roles: ['editor'] }
const editor = { id: 1, collection: 'users', roles: ['editor'] }
test('a link to Payload\'s own list filtered to the unused files — nothing is deleted', async () => {
const p = payload({ media: [{ filename: 'a.jpg', id: 'm1' }, { filename: 'plan.pdf', id: 'm2' }, { filename: 'b.jpg', id: 'm3' }], pages: [{ hero: 'm1', text: 'see /api/media/file/plan.pdf' }] })
const p = payload({ media: [{ id: 'm1', filename: 'a.jpg' }, { id: 'm2', filename: 'plan.pdf' }, { id: 'm3', filename: 'b.jpg' }], pages: [{ hero: 'm1', text: 'see /api/media/file/plan.pdf' }] })
const html = renderToStaticMarkup(await UnusedMediaNotice({ adminRoute: '/admin', collection: 'media', i18n: { language: 'en' }, payload: p as never, user: editor }))
expect(html).toContain('1 file is not used on any page, entry or setting.')
expect(html).toContain('href="/admin/collections/media?where[id][in][0]=m3"')
@@ -171,10 +171,10 @@ describe('unused media in the panel (item 12)', () => {
})
test('nothing for a visitor account or when every file is used; only a hint when the site is too big to check here', async () => {
const used = payload({ media: [{ filename: 'a.jpg', id: 'm1' }], pages: [{ hero: 'm1' }] })
const used = payload({ media: [{ id: 'm1', filename: 'a.jpg' }], pages: [{ hero: 'm1' }] })
expect(await UnusedMediaNotice({ collection: 'media', payload: used as never, user: editor })).toBeNull()
expect(await UnusedMediaNotice({ collection: 'media', payload: used as never, user: null })).toBeNull()
const broken = { ...used, find: async ({ collection }: { collection: string }) => { if (collection === 'pages') {throw new Error('no')} return { docs: [{ filename: 'a.jpg', id: 'm1' }] } } }
const broken = { ...used, find: async ({ collection }: { collection: string }) => { if (collection === 'pages') {throw new Error('no')} return { docs: [{ id: 'm1', filename: 'a.jpg' }] } } }
expect(renderToStaticMarkup(await UnusedMediaNotice({ collection: 'media', payload: broken as never, user: editor }))).toContain('too many documents to check')
})
})
+1 -1
View File
@@ -70,7 +70,7 @@ describe('stripImageMetadata', () => {
describe('buildOptimizeUploadHook: metadata on uploads that pass the limits', () => {
const run = async (data: Buffer, options = {}) => {
const file = { data, mimetype: 'image/jpeg', name: 'photo.jpg', size: data.length }
const file = { name: 'photo.jpg', data, mimetype: 'image/jpeg', size: data.length }
await buildOptimizeUploadHook(options)({ args: { data: {} }, operation: 'create', req: { file, i18n: { language: 'en' }, payload: { config: { sharp } } } } as never)
return file
}