@noxsoft/tailor-next
v0.1.1
Published
Tailor for Next.js (App Router): SSR-safe provider and a cookie read on the server so the first paint is the person's own layout.
Readme
@noxsoft/tailor-next
The Next.js (App Router) adapter for Tailor (@noxsoft/tailor-core). The server renders the person's own layout, so there is no flash of the default and no hydration mismatch.
// app/tailor.tsx (a client module: the registry holds components)
"use client";
import { TailorNextProvider } from "@noxsoft/tailor-next";
export function Providers({ initialState, children }) {
return <TailorNextProvider registry={registry} defaultConfig={defaultConfig} initialState={initialState}>{children}</TailorNextProvider>;
}
// app/layout.tsx (a server component)
import { cookies } from "next/headers";
import { readTailorState } from "@noxsoft/tailor-next/server";
const initialState = await readTailorState(await cookies());
<Providers initialState={initialState}><Shell>{children}</Shell></Providers>Shell is a client component that renders <TailorRoot route={usePathname()}> with your <Slot>s, as in @noxsoft/tailor-react.
How it works:
- Every save also writes the active config to a cookie. It is deflated, base64url-encoded and split over up to 6 cookies of 3800 bytes.
readTailorStatereads the cookie on the server, and the first render uses it.- After hydration, the full state (every saved layout, the history) loads from the real storage. That is localStorage by default, or pass
storage, such asasyncStoragefor your API. - Nothing is saved before that load.
@noxsoft/tailor-next/server doesn't import Next, so it works with any cookie store that has get(name).
MIT
