@k8ordo/framework 1.1.0 → 1.2.1

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.
@@ -98,16 +98,30 @@ as it checks every route file's.
98
98
 
99
99
  ## How a page is sent
100
100
 
101
+ **Each page loads its own.** `page.tsx`, `not-found.tsx`, `route.ts` and
102
+ `fallback.tsx` are imported when a request reaches them, so the client
103
+ components each renders and the CSS each imports — its Server Components'
104
+ CSS Modules included — go only to the pages that render it. What a
105
+ `layout.tsx`, `error.tsx` or `loading.tsx` imports, every page below it
106
+ loads: import CSS every page needs in the root layout. A route file imported
107
+ from anywhere else — a layout importing an export of a page — is in every
108
+ page again, and the build warns, naming it.
109
+
101
110
  **Under `mode: 'server'` an async page answers, then streams.** The document
102
111
  waits for the page's own component — its data — before anything is sent,
103
112
  because the page may still say `notFound()`
104
113
  ([Errors](errors.md#a-page-that-is-not-there)); what the page puts under a
105
114
  `<Suspense>` follows in the same response as it arrives. The browser hydrates
106
- when the last of it is in place, not before: a boundary still on its way
107
- cannot be hydrated, and a context that changes as the page hydrates — a
108
- colour scheme read from the browser — would make React render it again
109
- beside the copy still streaming in. Until then the page is what it is
110
- without JavaScript: links load documents and forms post.
115
+ when the last of it is in place and the client components it renders have
116
+ loaded, not before: a boundary still on its way cannot be hydrated, and a
117
+ context that changes as the page hydrates — a colour scheme read from the
118
+ browser — would make React render it again beside the copy still streaming
119
+ in, or put a boundary's fallback in place of a component still loading.
120
+ Until then the page is what it is without JavaScript: links load documents
121
+ and forms post. A client navigation likewise keeps the page on screen until
122
+ the next one's client components have loaded; what the next page puts under
123
+ a `<Suspense>` of its own — a `loading.tsx` is one — shows its fallback until
124
+ it arrives.
111
125
 
112
126
  **Under `mode: 'static'` a file is written whole.** The build waits for every
113
127
  `<Suspense>` boundary on the page and writes each in place, so a file never
@@ -318,12 +332,14 @@ source, so it is yours to read:
318
332
  // .k8ordo/routes.gen.ts
319
333
  import { defineRoutes } from '@k8ordo/framework/generated';
320
334
  import type { ParamsOf, ParsedParams } from '@k8ordo/framework/generated';
335
+ import { lazy } from 'react';
321
336
  import type { ComponentType, ReactNode } from 'react';
322
337
 
323
338
  import layout from '../src/routes/layout';
324
- import page from '../src/routes/page';
325
- import products_id_page from '../src/routes/products/[id]/page';
326
- import products_page from '../src/routes/products/page';
339
+
340
+ const page = () => import('../src/routes/page');
341
+ const products_page = () => import('../src/routes/products/page');
342
+ const products_id_page = () => import('../src/routes/products/[id]/page');
327
343
 
328
344
  type Page<P extends string, S extends readonly unknown[] = []> = ComponentType<{
329
345
  params: ParsedParams<P, S>;
@@ -339,6 +355,12 @@ export const paramSchemas = {} as const;
339
355
 
340
356
  export const searchReaders = {} as const;
341
357
 
358
+ export const pageModules = {
359
+ '/': page,
360
+ '/products': products_page,
361
+ '/products/:id': products_id_page,
362
+ } as const;
363
+
342
364
  export const routeModules = {} as const;
343
365
 
344
366
  export const guards = {} as const;
@@ -351,11 +373,11 @@ export const routes = defineRoutes({
351
373
  '/': {
352
374
  layout: layout satisfies Layout<'/'>,
353
375
  children: {
354
- '/': page satisfies Page<'/'>,
376
+ '/': lazy(page) satisfies Page<'/'>,
355
377
  '/products': {
356
378
  children: {
357
- '/': products_page satisfies Page<'/products'>,
358
- '/:id': products_id_page satisfies Page<'/products/:id'>,
379
+ '/': lazy(products_page) satisfies Page<'/products'>,
380
+ '/:id': lazy(products_id_page) satisfies Page<'/products/:id'>,
359
381
  },
360
382
  },
361
383
  },
@@ -365,20 +387,24 @@ export const routes = defineRoutes({
365
387
 
366
388
  Each `satisfies` checks a route file's props against the pattern its directory
367
389
  puts it under — a type check, so `tsc` reports a mismatch and `vite build`,
368
- which does not type-check, passes. Under `mode: 'server'` the `Page` and
390
+ which does not type-check, passes. A page and a not-found stand in `routes`
391
+ as `lazy()` over what imports them: `pageModules` lists, per pattern, what
392
+ imports the page or the not-found that answers it, and the handler renders
393
+ what it imported in that place. Under `mode: 'server'` the `Page` and
369
394
  `Layout` types also carry `request`, typed by `RouteRequest` from
370
395
  `@k8ordo/framework/server`. `redirects` is where each `redirect.ts`
371
396
  sends the visitor once the walk of `routes` reaches its pattern,
372
397
  `paramSchemas` holds, per page pattern, the schemas it runs when the walk
373
- reaches that pattern, before the page renders, `routeModules` the `route.ts`
374
- that answers a pattern (the place of each, and of each `redirect.ts`, in
375
- `routes` is held by a component that renders nothing), `guards` the
376
- `guard.ts` files that run before a pattern answers, outer first,
398
+ reaches that pattern, before the page renders — a page's own read off the
399
+ page once the walk has imported it — `routeModules` what imports the
400
+ `route.ts` that answers a pattern (the place of each, and of each
401
+ `redirect.ts`, in `routes` is held by a component that renders nothing),
402
+ `guards` the `guard.ts` files that run before a pattern answers, outer first,
377
403
  `searchReaders` what reads the search for a page that exports `search`, and
378
- `fallbacks`, under `mode: 'static'`, the `fallback.tsx` beside a page and the
379
- parameters its shell may leave to the browser (under `mode: 'server'` it is
380
- always empty, and no `fallback.tsx` is imported); all six are empty here
381
- because no route file declares any.
404
+ `fallbacks`, under `mode: 'static'`, what imports the `fallback.tsx` beside a
405
+ page and the parameters its shell may leave to the browser (under
406
+ `mode: 'server'` it is always empty, and no `fallback.tsx` is imported); all
407
+ six are empty here because no route file declares any.
382
408
 
383
409
  `.k8ordo/register.gen.ts` registers that table with the framework — and with
384
410
  `@k8ordo/state` when the application depends on it — so typed paths work
@@ -426,12 +452,26 @@ Neither file names `@k8ordo/router`: they import from
426
452
  `@k8ordo/framework/generated`, so the application's code, generated or not,
427
453
  reads only the framework.
428
454
 
429
- `vite build` and `vite dev` write both files as they start, and nothing else
430
- does, so a fresh clone — a CI checkout among them — has neither until one of
431
- them runs. Run the build before `tsc`:
432
-
433
- ```bash
434
- vite build && tsc --noEmit
455
+ `vite build` and `vite dev` write both files as they start, so a fresh
456
+ clone — a CI checkout among them — has neither until something writes them.
457
+ `k8ordo generate`, the package's command, writes them and stops there: it
458
+ reads the Vite config in the working directory as `vite build` does, so the
459
+ `mode` and `routesDir` given to `framework()` are the ones it uses, then
460
+ builds nothing and renders no page — `paths` is never called, and nothing a
461
+ page reads is touched. A `routes/` with the problems of
462
+ [What the build refuses](#what-the-build-refuses) fails it as it fails the
463
+ build, with `routes/ is not a valid pathname space:` and every problem
464
+ named, and nothing is written. What `mode: 'static'` refuses on top of
465
+ those — a `guard.ts`, a `route.ts` answering more than `GET`, a page
466
+ reading `search`, an `export *`, a Server Action, whatever `paths`
467
+ returns — it does not check, so its success is not the build's. Run it
468
+ before `tsc`; it is also how a CI job without the data a build reads — the
469
+ database behind `paths`, say — has the types:
470
+
471
+ ```yaml
472
+ # .github/workflows/ci.yml, in the application's directory
473
+ - run: pnpm exec k8ordo generate
474
+ - run: pnpm exec tsc --noEmit
435
475
  ```
436
476
 
437
477
  Without the files, `tsc` checks against no table: `href` takes any string,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@k8ordo/framework",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "The k8ordo framework: routes/ compiled into React Server Components, run with or without a server.",
5
5
  "keywords": [
6
6
  "k8ordo",
@@ -23,6 +23,9 @@
23
23
  "type": "git",
24
24
  "url": "git+https://github.com/k35o/k8ordo.git"
25
25
  },
26
+ "bin": {
27
+ "k8ordo": "./dist/cli.mjs"
28
+ },
26
29
  "files": [
27
30
  "dist/**",
28
31
  "docs/**"
@@ -73,13 +76,13 @@
73
76
  "devDependencies": {
74
77
  "@arethetypeswrong/cli": "0.18.5",
75
78
  "@k8ordo/framework-engine": "^0.1.1",
76
- "@k8ordo/router": "^1.1.0",
79
+ "@k8ordo/router": "^1.2.1",
77
80
  "@types/compressible": "2.0.3",
78
81
  "@types/fresh": "0.5.3",
79
82
  "@types/mime-types": "3.0.1",
80
83
  "@types/range-parser": "1.2.7",
81
84
  "@types/react": "19.3.0",
82
- "oxc-transform-react": "0.154.0",
85
+ "oxc-transform-react": "0.152.0",
83
86
  "publint": "0.3.25",
84
87
  "react": "19.3.1",
85
88
  "react-dom": "19.3.1",
@@ -89,7 +92,7 @@
89
92
  "vitest": "5.0.5"
90
93
  },
91
94
  "peerDependencies": {
92
- "@k8ordo/router": "^1.1.0",
95
+ "@k8ordo/router": "^1.2.1",
93
96
  "oxc-transform-react": "^0.152.0",
94
97
  "react": ">=19.3.0",
95
98
  "react-dom": ">=19.3.0",