hadars 0.1.40 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -55
- package/dist/{chunk-2ENP7IAW.js → chunk-LY5MTHFV.js} +360 -203
- package/dist/cli.js +424 -262
- package/dist/lambda.cjs +387 -229
- package/dist/lambda.js +63 -45
- package/dist/slim-react/index.cjs +361 -203
- package/dist/slim-react/index.d.cts +24 -8
- package/dist/slim-react/index.d.ts +24 -8
- package/dist/slim-react/index.js +3 -1
- package/dist/ssr-render-worker.js +349 -219
- package/package.json +1 -1
- package/src/build.ts +7 -6
- package/src/lambda.ts +6 -2
- package/src/slim-react/context.ts +2 -1
- package/src/slim-react/index.ts +21 -18
- package/src/slim-react/render.ts +379 -240
- package/src/slim-react/renderContext.ts +105 -45
- package/src/ssr-render-worker.ts +10 -43
- package/src/utils/cookies.ts +1 -1
- package/src/utils/response.tsx +62 -33
- package/src/utils/serve.ts +29 -27
- package/src/utils/ssrHandler.ts +54 -25
- package/src/utils/staticFile.ts +2 -7
package/README.md
CHANGED
|
@@ -41,6 +41,7 @@ Bring your own router (or none), keep your components as plain React, and get SS
|
|
|
41
41
|
| DOMContentLoaded | **88 ms** | 126 ms |
|
|
42
42
|
| Load | **155 ms** | 173 ms |
|
|
43
43
|
<!-- BENCHMARK_END -->
|
|
44
|
+
|
|
44
45
|
## Quick start
|
|
45
46
|
|
|
46
47
|
Scaffold a new project in seconds:
|
|
@@ -144,66 +145,11 @@ const UserCard = ({ userId }: { userId: string }) => {
|
|
|
144
145
|
- **Client (hydration)** - reads the pre-resolved value from the hydration cache serialised by the server; `fn()` is never called in the browser
|
|
145
146
|
- **Client (navigation)** - when a component mounts during client-side navigation and its key is not in the cache, hadars fires a single `GET <current-url>` with `Accept: application/json`; all `useServerData` calls within the same render are batched into one request and suspended via React Suspense until the server returns the JSON data map
|
|
146
147
|
|
|
147
|
-
## HadarsHead
|
|
148
|
-
|
|
149
|
-
`HadarsHead` (exported as `Head`) manages `<title>`, `<meta>`, `<link>`, `<script>`, and `<style>` tags across both SSR and client renders. On the server it collects tags into the HTML `<head>`; on the client it upserts them into `document.head`.
|
|
150
|
-
|
|
151
|
-
```tsx
|
|
152
|
-
import { HadarsHead } from 'hadars';
|
|
153
|
-
|
|
154
|
-
const Page = ({ context }) => (
|
|
155
|
-
<HadarsContext context={context}>
|
|
156
|
-
<HadarsHead status={200}>
|
|
157
|
-
<title>My page</title>
|
|
158
|
-
<meta name="description" content="A great page" />
|
|
159
|
-
<meta property="og:title" content="My page" />
|
|
160
|
-
<link rel="canonical" href="https://example.com/page" />
|
|
161
|
-
<link rel="stylesheet" href="/styles/page.css" />
|
|
162
|
-
<style data-id="page-critical">{`body { margin: 0 }`}</style>
|
|
163
|
-
<script src="/vendor/analytics.js" async />
|
|
164
|
-
<script data-id="inline-config" dangerouslySetInnerHTML={{ __html: 'var X=1' }} />
|
|
165
|
-
</HadarsHead>
|
|
166
|
-
...
|
|
167
|
-
</HadarsContext>
|
|
168
|
-
);
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
### Deduplication
|
|
172
|
-
|
|
173
|
-
Each element type has a natural dedup key derived from its identifying attributes. Rendering the same `<Head>` block on multiple components or re-renders will not produce duplicate tags.
|
|
174
|
-
|
|
175
|
-
| Element | Dedup key |
|
|
176
|
-
|---|---|
|
|
177
|
-
| `<title>` | always singular — last write wins |
|
|
178
|
-
| `<meta name="…">` | `name` value |
|
|
179
|
-
| `<meta property="…">` | `property` value |
|
|
180
|
-
| `<meta http-equiv="…">` | `http-equiv` value |
|
|
181
|
-
| `<meta charSet>` | singular — one charset per page |
|
|
182
|
-
| `<link rel="…" href="…">` | `rel` + `href` (+ `as` when present) |
|
|
183
|
-
| `<link rel="…">` (no href) | `rel` alone (e.g. `rel="preconnect"`) |
|
|
184
|
-
| `<script src="…">` | `src` URL |
|
|
185
|
-
| `<script data-id="…">` | `data-id` value |
|
|
186
|
-
| `<style data-id="…">` | `data-id` value |
|
|
187
|
-
|
|
188
|
-
### `data-id` for inline tags
|
|
189
|
-
|
|
190
|
-
Inline `<script>` (no `src`) and `<style>` elements have no natural URL to key on. Provide a `data-id` prop so hadars can find and update the same element across re-renders rather than appending a duplicate:
|
|
191
|
-
|
|
192
|
-
```tsx
|
|
193
|
-
<HadarsHead>
|
|
194
|
-
<style data-id="critical-css">{criticalStyles}</style>
|
|
195
|
-
<script data-id="gtm-config" dangerouslySetInnerHTML={{ __html: gtmSnippet }} />
|
|
196
|
-
</HadarsHead>
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
Omitting `data-id` on these elements triggers a console warning at render time and falls back to append-only behaviour (safe for one-time static tags, not for anything that re-renders).
|
|
200
|
-
|
|
201
148
|
## Data lifecycle hooks
|
|
202
149
|
|
|
203
150
|
| Hook | Runs on | Purpose |
|
|
204
151
|
|---|---|---|
|
|
205
152
|
| `getInitProps` | server | Fetch server-side data from the `HadarsRequest` |
|
|
206
|
-
| `getAfterRenderProps` | server | Inspect the rendered HTML (e.g. extract critical CSS) |
|
|
207
153
|
| `getFinalProps` | server | Strip server-only fields before props are serialised to the client |
|
|
208
154
|
| `getClientProps` | client | Enrich props with browser-only data (localStorage, device APIs) |
|
|
209
155
|
|