Skip to content

Commit 1a8774e

Browse files
authored
docs: SSR storybook guide + minimal NextJS App Router example (#462)
* docs: added SSR integration guide for Next.js, SvelteKit and other SSR frameworks Documents the two levels reachable today: avoiding server-side crashes (deferred import of elements.js) and HTML-first + hydration (static slotted markup emitted server-side). Real SSR with Declarative Shadow DOM via @lit-labs/ssr is explicitly out of scope pending kit fixes. Adds cross-links from the React/Svelte/Vue/Angular framework pages and from the technical documentation, plus a warning about the Turbopack CSS parse error caused by an upstream bootstrap-italia bug. Refs #360 * feat(examples): added Next.js example app with SSR-safe kit integration Minimal Next.js 16 (App Router, static export) app demonstrating the patterns from the Framework/SSR Storybook page: elements.js import deferred to useEffect with static slotted markup (HTML-first), and next/dynamic with ssr:false for client-only components. Wired into the examples preview pipeline. Uses --webpack because Turbopack rejects a malformed CSS custom property in styles.css inherited from an upstream bootstrap-italia bug (var(-bsi-spacing-inset-m), missing dash). Refs #360 * docs: storybook docs and nextjs app minimal example
1 parent 7b23069 commit 1a8774e

27 files changed

Lines changed: 1721 additions & 0 deletions

.changeset/ssr-docs-issue-360.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@italia/dev-kit-italia': minor
3+
---
4+
5+
Added SSR documentation and a Next.js example app: how to avoid crashes and reach HTML-first hydration in Next.js, SvelteKit and other SSR frameworks (#360)

examples/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@ npm run dev
1313

1414
Una volta avviato il server di sviluppo, l'applicazione sarà accessibile all'indirizzo [http://localhost:5173](http://localhost:5173).
1515

16+
## Next.js
17+
18+
Questa applicazione è generata con [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app) (App Router) e usa l'esportazione statica di Next.js (`output: 'export'`). Per avviare l'applicazione di esempio:
19+
20+
```bash
21+
cd next-app
22+
npm install
23+
npm run dev
24+
```
25+
26+
Una volta avviato il server di sviluppo, l'applicazione sarà accessibile all'indirizzo [http://localhost:3000/next-app](http://localhost:3000/next-app).
27+
28+
Questo esempio mostra come integrare i web component del kit in un contesto con rendering lato server senza causare crash in fase di build/prerendering, secondo i pattern documentati nella pagina Storybook "Framework/SSR".
29+
1630
## Angular
1731

1832
Questa applicazione è generata e gestita con [Angular CLI](https://angular.io/cli).

examples/next-app/.gitignore

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.*
7+
.yarn/*
8+
!.yarn/patches
9+
!.yarn/plugins
10+
!.yarn/releases
11+
!.yarn/versions
12+
13+
# testing
14+
/coverage
15+
16+
# next.js
17+
/.next/
18+
/out/
19+
20+
# production
21+
/build
22+
23+
# misc
24+
.DS_Store
25+
*.pem
26+
27+
# debug
28+
npm-debug.log*
29+
yarn-debug.log*
30+
yarn-error.log*
31+
.pnpm-debug.log*
32+
33+
# env files (can opt-in for committing if needed)
34+
.env*
35+
36+
# vercel
37+
.vercel
38+
39+
# typescript
40+
*.tsbuildinfo
41+
next-env.d.ts

examples/next-app/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
legacy-peer-deps=true

examples/next-app/.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
24

examples/next-app/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Esempio di integrazione: Next.js (App Router)
2+
3+
Applicazione Next.js 16 minimale che integra i web component di `@italia/dev-kit-italia` in un contesto con rendering lato server, senza causare crash in fase di build/prerendering. Replica i pattern documentati nella pagina Storybook "Framework/SSR":
4+
5+
- `components/KitDemo.js` — import di `elements.js` differito in `useEffect`, con markup e contenuto slottato statici nel JSX così che il server li emetta comunque (HTML-first);
6+
- `components/ClientOnlyDemo.js` + `components/NoSsrKit.js` — esclusione completa dal render server tramite `next/dynamic` con `ssr: false`, per componenti privi di markup utile lato server.
7+
8+
## Avvio
9+
10+
```bash
11+
npm install
12+
npm run dev
13+
```
14+
15+
L'applicazione sarà accessibile all'indirizzo [http://localhost:3000/next-app](http://localhost:3000/next-app) (il `basePath` è configurato per il deploy statico sotto `/next-app/`).
16+
17+
## Nota su Turbopack
18+
19+
Gli script `dev` e `build` usano `--webpack` anziché Turbopack (default in Next.js 16): il file `styles.css` del kit contiene attualmente una regola CSS malformata ereditata da `bootstrap-italia` (`var(-bsi-spacing-inset-m)`, manca un trattino) che il parser CSS di Turbopack rifiuta con un errore bloccante, mentre webpack la tollera. Il flag potrà essere rimosso quando il bug sarà corretto a monte.

examples/next-app/app/favicon.ico

25.3 KB
Binary file not shown.

examples/next-app/app/globals.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
body {
2+
min-height: 100vh;
3+
}
4+
5+
main {
6+
max-width: 60rem;
7+
margin: 0 auto;
8+
padding: 2rem 1rem;
9+
}

examples/next-app/app/layout.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import '@italia/dev-kit-italia/fonts.css';
2+
import '@italia/dev-kit-italia/styles.css';
3+
import './globals.css';
4+
5+
import Header from '../components/Header';
6+
import Footer from '../components/Footer';
7+
import KitElementsLoader from '../components/KitElementsLoader';
8+
9+
export const metadata = {
10+
title: 'Dev Kit Italia + Next.js',
11+
description: 'Esempio di integrazione SSR-safe di @italia/dev-kit-italia con Next.js App Router.',
12+
};
13+
14+
export default function RootLayout({ children }) {
15+
return (
16+
<html lang="it">
17+
<body>
18+
<KitElementsLoader />
19+
<Header />
20+
{children}
21+
<Footer />
22+
</body>
23+
</html>
24+
);
25+
}

examples/next-app/app/page.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import KitDemo from '../components/KitDemo';
2+
import ClientOnlyDemo from '../components/ClientOnlyDemo';
3+
4+
export default function Home() {
5+
return (
6+
<main className="container my-4">
7+
<it-callout variant="primary">
8+
<it-icon slot="icon" name="it-info-circle" aria-hidden="true"></it-icon>
9+
<span slot="title">Solo integrazione SSR</span>
10+
<p>
11+
Questo esempio Next.js mostra soltanto l&rsquo;integrazione lato server (SSR) del Dev Kit Italia. Per esempi
12+
completi dei componenti in React, consulta l&rsquo;app di esempio React.
13+
</p>
14+
</it-callout>
15+
16+
<h1>Dev Kit Italia + Next.js</h1>
17+
<p>
18+
Questo esempio integra i web component di <code>@italia/dev-kit-italia</code> in una app Next.js (App Router)
19+
senza causare crash durante il rendering lato server, secondo i pattern descritti nella pagina Storybook
20+
&ldquo;Framework/SSR&rdquo;.
21+
</p>
22+
23+
<KitDemo />
24+
<ClientOnlyDemo />
25+
</main>
26+
);
27+
}

0 commit comments

Comments
 (0)