@kerf-js/start 0.1.0 → 0.1.1-nightly.20261112.42
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 +3 -0
- package/package.json +2 -2
- package/src/run/shape-styles.ts +3 -1
- package/src/run.tsx +3 -0
- package/src/vite/module-hooks.mjs +1 -0
- package/src/vite/route-modules.mjs +11 -5
- package/src/vite/shared.mjs +25 -3
package/README.md
CHANGED
|
@@ -331,6 +331,9 @@ export const skeleton = HomeSkeleton
|
|
|
331
331
|
It runs before the page's code loads, so it may use only `div span section article main header footer p h1`–`h6
|
|
332
332
|
ul ol li`, string `class` and `data-*` attributes, and text. Anything else warns and leaves no skeleton.
|
|
333
333
|
|
|
334
|
+
In a build, a skeleton's stylesheet text loads with the router once the page is up, not with the page's own code. A
|
|
335
|
+
navigation that comes before it keeps the old page up until the new one arrives.
|
|
336
|
+
|
|
334
337
|
## Data loading
|
|
335
338
|
|
|
336
339
|
`load` runs on the server for the first request and for each client navigation (the client fetches the route's data as
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kerf-js/start",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1-nightly.20261112.42",
|
|
4
4
|
"description": "kerf Start: file routes, server functions, streaming SSR, a database and auth",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"kerf"
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"vite": "8.3.5"
|
|
83
83
|
},
|
|
84
84
|
"peerDependencies": {
|
|
85
|
-
"@kerf-js/core": "^0.1.
|
|
85
|
+
"@kerf-js/core": "^0.1.1-nightly.20261112.42",
|
|
86
86
|
"better-auth": "^1.7.0",
|
|
87
87
|
"drizzle-orm": "^0.45.0",
|
|
88
88
|
"drizzle-zod": "^0.8.0",
|
package/src/run/shape-styles.ts
CHANGED
|
@@ -23,7 +23,9 @@ export function acquireShapeStyles(
|
|
|
23
23
|
build: string | null | undefined,
|
|
24
24
|
text: string[],
|
|
25
25
|
): SheetLease | null {
|
|
26
|
-
|
|
26
|
+
// A sheet that hasn't arrived yet (`shapeStyles`, after the page) leaves no shape, and the old page stays up.
|
|
27
|
+
if (!doc.head || text.some((css) => typeof css !== 'string' || /@import\b/i.test(css)))
|
|
28
|
+
return null
|
|
27
29
|
const key = JSON.stringify([build ?? null, text])
|
|
28
30
|
const entries = sheets.get(doc) ?? new Map<string, SheetEntry>()
|
|
29
31
|
if (!sheets.has(doc)) sheets.set(doc, entries)
|
package/src/run.tsx
CHANGED
|
@@ -55,6 +55,8 @@ export interface ClientRoutes {
|
|
|
55
55
|
load: Record<string, () => Promise<{ default?: Component }>>
|
|
56
56
|
/** Eager shape metadata, keyed by route or layout id. */
|
|
57
57
|
shapes?: RouteShapes
|
|
58
|
+
/** Loads the shapes' stylesheet text, in a build: the router calls it once the page is up. */
|
|
59
|
+
shapeStyles?: () => Promise<unknown>
|
|
58
60
|
/** Each island's code, by id: all a static level loads (PLAN §11). */
|
|
59
61
|
islands?: Record<string, () => Promise<{ default: Component }>>
|
|
60
62
|
}
|
|
@@ -65,6 +67,7 @@ export async function start(routes: ClientRoutes, options: { container?: Element
|
|
|
65
67
|
await Promise.all(prepared.loads)
|
|
66
68
|
const page = mount(prepared)
|
|
67
69
|
page.route.prepareShape = (id) => prepareRouteShape(routes, id, document)
|
|
70
|
+
void routes.shapeStyles?.().catch(() => {})
|
|
68
71
|
const navigation = new Navigation(routes, page)
|
|
69
72
|
client.navigate = navigation.go
|
|
70
73
|
listeners(navigation, () => (import.meta as Hot).hot)
|
|
@@ -279,6 +279,7 @@ async function clientRoutesModule(ctx, s, p, run) {
|
|
|
279
279
|
levels: new Map(files.map((file, i) => [file, sources[i].styles])),
|
|
280
280
|
overrides,
|
|
281
281
|
build: s.build || null,
|
|
282
|
+
lazy: s.dev === false,
|
|
282
283
|
}
|
|
283
284
|
const output = clientRoutes(s.manifest, s.abs, p, css)
|
|
284
285
|
s.shapeEntrySignatures = shared.signatures
|
|
@@ -199,16 +199,22 @@ export function shapeSignature(file) {
|
|
|
199
199
|
|
|
200
200
|
/**
|
|
201
201
|
* The routes table's stylesheets and `shapeEntry`. A stylesheet edit in `kerf dev` lands here instead of reloading the
|
|
202
|
-
* page: a shape reads its CSS when it's shown.
|
|
202
|
+
* page: a shape reads its CSS when it's shown. `lazy` (a build): the text is `shapeStyles()`, which the router calls once
|
|
203
|
+
* the page is up. A shape is for a navigation, so the page's own code doesn't carry a second copy of its sheets.
|
|
203
204
|
*/
|
|
204
|
-
function shapeStyles(files) {
|
|
205
|
+
function shapeStyles(files, lazy) {
|
|
205
206
|
const requests = files.map((file) => JSON.stringify(file + '?inline'))
|
|
206
207
|
const accept = requests.length
|
|
207
208
|
? `if (import.meta.hot) import.meta.hot.accept([${requests.join(', ')}], (mods) => mods.forEach((m, i) => { if (m) styles[i] = m.default }))\n`
|
|
208
209
|
: ''
|
|
209
|
-
|
|
210
|
+
const load = lazy
|
|
211
|
+
? `const styles = []
|
|
212
|
+
export const shapeStyles = () => Promise.all([${requests.map((r) => `import(${r})`).join(', ')}]).then((mods) => mods.forEach((m, i) => { styles[i] = m.default }))
|
|
213
|
+
`
|
|
214
|
+
: `${requests.map((request, i) => `import style${i} from ${request}`).join('\n')}
|
|
210
215
|
const styles = [${requests.map((_, i) => `style${i}`).join(', ')}]
|
|
211
|
-
${accept}
|
|
216
|
+
${accept}`
|
|
217
|
+
return `${load}const shapeEntry = (module, sheets, name, kind) => {
|
|
212
218
|
const component = Reflect.get(module, name)
|
|
213
219
|
const groupCss = Reflect.get(module, '$kerfShapeCss')
|
|
214
220
|
const lead = typeof groupCss === 'string' && groupCss ? [groupCss] : []
|
|
@@ -279,7 +285,7 @@ export function clientRoutes(manifest, abs, plan, css = {}) {
|
|
|
279
285
|
`${JSON.stringify(i.id)}: () => import(${JSON.stringify(i.file)}).then(({ $i${i.index}: d }) => ({ default: d }))`,
|
|
280
286
|
)
|
|
281
287
|
return `${shapeImports.join('\n')}
|
|
282
|
-
${shapeStyles([...styleFiles.keys()])}
|
|
288
|
+
${shapeStyles([...styleFiles.keys()], css.lazy)}
|
|
283
289
|
export const shapes = { ${shapes.join(', ')} }
|
|
284
290
|
export const build = ${JSON.stringify(css.build ?? null)}
|
|
285
291
|
export const table = ${JSON.stringify(table)}
|
package/src/vite/shared.mjs
CHANGED
|
@@ -44,12 +44,34 @@ export const SHEET_PIECES = '__KERF_SHEET_PIECES__'
|
|
|
44
44
|
*/
|
|
45
45
|
export const ENTRY_SHEETS = `${LATE_SHEETS}\n${REFUSED_SHEETS}\n`
|
|
46
46
|
|
|
47
|
+
const OWN = /[\\/]node_modules[\\/]@kerf-js[\\/]/
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Whether a module loads only behind one of kerf's own `import()`s: a split its package chose, such as the text engine
|
|
51
|
+
* behind `measure()`. Every other path, a static import or the app's own `import()` (the routes table's included),
|
|
52
|
+
* can bring it with a page.
|
|
53
|
+
*/
|
|
54
|
+
export function packageLazy(id, info, seen = new Set()) {
|
|
55
|
+
const m = info(id)
|
|
56
|
+
if (!m || m.isEntry) return false
|
|
57
|
+
seen.add(id)
|
|
58
|
+
if (m.dynamicImporters.some((d) => !OWN.test(d))) return false
|
|
59
|
+
return m.importers.every((i) => seen.has(i) || packageLazy(i, info, seen))
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const kitGroup = (name) => (id, ctx) => (packageLazy(id, (m) => ctx.getModuleInfo(m)) ? null : name)
|
|
63
|
+
|
|
47
64
|
/**
|
|
48
65
|
* kerf's own packages from an install, as one chunk of icons and one of what two routes share. Left alone they're a chunk
|
|
49
66
|
* per component: 31 scripts and 18 sheets for an admin page (Solid's: 16 in all), each its own request and its own
|
|
50
|
-
* compression, and 53 KB against 46. An app's own code splits as it likes
|
|
67
|
+
* compression, and 53 KB against 46. An app's own code splits as it likes, and so does a package's own `import()`: the
|
|
68
|
+
* kit every page loads would otherwise carry it.
|
|
51
69
|
*/
|
|
52
70
|
export const KIT_CHUNKS = [
|
|
53
|
-
{
|
|
54
|
-
|
|
71
|
+
{
|
|
72
|
+
name: kitGroup('icons'),
|
|
73
|
+
test: /[\\/]node_modules[\\/]@kerf-js[\\/]veneer-icons[\\/]/,
|
|
74
|
+
priority: 2,
|
|
75
|
+
},
|
|
76
|
+
{ name: kitGroup('kit'), test: OWN, minShareCount: 2, priority: 1 },
|
|
55
77
|
]
|