Lazy 404: createNotFoundPage({ load }) + renderNotFoundView, NotFoundLoader
Next puts a layout's not-found tree into the RSC payload of every page under it. The eager
createNotFoundPage({ blocks }) rendered the panel's 404 page there in every locale, so with
404 = homepage each page shipped the homepage twice (homepage HTML 195 -> 146 KB gzip).
With { load } only <NotFoundLoader> is in the payload; the content comes from the project's
server action (renderNotFoundView, locale checked against configured locales) when a 404 shows.
The eager variant is unchanged. Docs: pages.md, i18n.md, AGENT.md, PROGRAMISTA, ipal-setup, CHANGELOG.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
8b35986635
commit
166bf51e53
+34
-8
@@ -62,18 +62,44 @@ Site Settings → System Pages → **404 (Not Found)**. Edytor wybiera:
|
||||
- stronę główną (część klientów tak woli), **albo**
|
||||
- nic → projekt pokazuje wbudowany fallback z `not-found.tsx`.
|
||||
|
||||
Projekt — `app/(frontend)/[locale]/not-found.tsx`, jedna linia (od 1.9.2):
|
||||
Projekt — dwa pliki w `app/(frontend)/[locale]/` (od 1.12.0, **wariant leniwy — zalecany**):
|
||||
|
||||
```tsx
|
||||
import { createNotFoundPage } from '@intecion/ipal-kit/rsc'
|
||||
```ts
|
||||
// notFoundView.ts — server action z treścią 404 w JEDNYM języku
|
||||
'use server'
|
||||
import { renderNotFoundView } from '@intecion/ipal-kit/rsc'
|
||||
import * as content from '@/lib/content'
|
||||
import { blockRegistry } from '@/blocks/registry'
|
||||
|
||||
export default createNotFoundPage(content, {
|
||||
blocks: blockRegistry,
|
||||
fallback: <h1>404</h1>, // gdy w panelu nie wybrano strony 404 (albo per język: (locale) => …)
|
||||
// blockProps: async ({ locale }) => ({ formTexts: await content.getFormTexts(locale), sendForm }),
|
||||
})
|
||||
export async function loadNotFoundView(locale: string) {
|
||||
return renderNotFoundView(content, {
|
||||
blocks: blockRegistry,
|
||||
fallback: <h1>404</h1>, // gdy w panelu nie wybrano strony 404 (albo per język: (locale) => …)
|
||||
// blockProps: async ({ locale }) => ({ formTexts: await content.getFormTexts(locale), sendForm }),
|
||||
}, locale)
|
||||
}
|
||||
```
|
||||
```tsx
|
||||
// not-found.tsx
|
||||
import { createNotFoundPage } from '@intecion/ipal-kit/rsc'
|
||||
import * as content from '@/lib/content'
|
||||
import { loadNotFoundView } from './notFoundView'
|
||||
|
||||
export default createNotFoundPage(content, { load: loadNotFoundView })
|
||||
```
|
||||
(`fallback` z JSX → plik `notFoundView.tsx`.)
|
||||
|
||||
**Dlaczego leniwy:** Next wkłada drzewo `not-found` layoutu do danych RSC (`self.__next_f`) **każdej** strony
|
||||
pod nim — router potrzebuje go do 404 po stronie klienta. Wariant natychmiastowy renderuje tam stronę 404 z panelu
|
||||
w każdym języku, więc każda strona wiezie ją w HTML (404 = strona główna przy 2 językach: HTML strony głównej
|
||||
195 → 146 KB gzip, strony kontaktu 153 → 104 KB). W wariancie leniwym w danych jest tylko `<NotFoundLoader>`
|
||||
(`/client`); treść przychodzi z server action dopiero, gdy 404 się wyświetla. Język z adresu (`/en/...`);
|
||||
`renderNotFoundView` przyjmuje tylko skonfigurowane języki (inne → domyślny). Status 404 bez zmian; treść
|
||||
pojawia się po hydratacji (strona 404 i tak nie jest indeksowana).
|
||||
|
||||
Wariant natychmiastowy (do 1.11.x jedyny) — treść już w HTML, za cenę rozmiaru każdej strony:
|
||||
```tsx
|
||||
export default createNotFoundPage(content, { blocks: blockRegistry, fallback: <h1>404</h1> })
|
||||
```
|
||||
Robi dokładnie to, co pełny plik poniżej (widok dla każdego języka + `LocaleView`, bez `headers()`).
|
||||
|
||||
|
||||
Reference in New Issue
Block a user