@nifrajs/web-svelte 5.0.0 → 5.1.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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,aAAa,EAAe,MAAM,cAAc,CAAA;AAqF9D,8EAA8E;AAC9E,eAAO,MAAM,aAAa,EAAE,aA8B3B,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,aAAa,EAAoC,MAAM,cAAc,CAAA;AAgGnF,8EAA8E;AAC9E,eAAO,MAAM,aAAa,EAAE,aA6B3B,CAAA"}
package/dist/index.js CHANGED
@@ -45,31 +45,37 @@ function oneChunk(html) {
45
45
  },
46
46
  });
47
47
  }
48
+ /** The body of one render; what `<svelte:head>` rendered goes into the document's `<head>`. */
49
+ function bodyOf(Chain, props, options) {
50
+ const out = render(Chain, { props });
51
+ if (options?.parts !== undefined)
52
+ options.parts.head += out.head;
53
+ return out.body;
54
+ }
48
55
  /** The Svelte server render adapter - pass to @nifrajs/web's `renderPage`. */
49
56
  export const svelteAdapter = {
57
+ documentParts: true,
50
58
  // Svelte SSR is already synchronous + string-based, so this is the native shape: `renderToString`
51
59
  // returns the body directly (renderPage buffers it on the non-deferred fast path), and
52
60
  // `renderToStream` wraps the same string in a one-chunk stream for the deferred path. No streaming
53
61
  // renderer to skip here - but going straight to a string avoids the per-request stream allocation.
54
62
  // The seam allows `string | Promise<string>`, so the first render can resolve `Chain` while every
55
63
  // render after it stays a plain synchronous call - see `loadChain`.
56
- renderToString(chain, props) {
64
+ renderToString(chain, props, options) {
57
65
  const Chain = loadChain();
58
66
  const props$ = { chain, props, layoutData: props.layoutData };
59
67
  return Chain instanceof Promise
60
- ? Chain.then((C) => render(C, { props: props$ }).body)
61
- : render(Chain, { props: props$ }).body;
68
+ ? Chain.then((C) => bodyOf(C, props$, options))
69
+ : bodyOf(Chain, props$, options);
62
70
  },
63
- renderToStream(chain, props) {
71
+ renderToStream(chain, props, options) {
64
72
  // `Chain` folds the layout chain (page innermost gets `props`; layouts wrap via their `children`
65
- // snippet). Svelte's `render` returns { head, body }; the body goes into #root. (Svelte's dynamic
66
- // `head` - from <svelte:head> - isn't surfaced through the seam's static `hydrationHead`; nifra's
67
- // own meta/head API manages the document head instead.)
73
+ // snippet). Svelte's `render` returns { head, body }; the body goes into #root.
68
74
  const Chain = loadChain();
69
75
  const props$ = { chain, props, layoutData: props.layoutData };
70
76
  return Chain instanceof Promise
71
- ? Chain.then((C) => oneChunk(render(C, { props: props$ }).body))
72
- : oneChunk(render(Chain, { props: props$ }).body);
77
+ ? Chain.then((C) => oneChunk(bodyOf(C, props$, options)))
78
+ : oneChunk(bodyOf(Chain, props$, options));
73
79
  },
74
80
  // Svelte's client `hydrate` reconciles against the existing DOM; no per-document bootstrap script is
75
81
  // needed (contrast Solid's generateHydrationScript) - the seam allows the empty string.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAE9C,OAAO,EAAE,MAAM,IAAI,aAAa,EAAE,MAAM,eAAe,CAAA;AAkCvD,IAAI,cAAiD,CAAA;AACrD,IAAI,YAAwD,CAAA;AAC5D;;;;GAIG;AACH,IAAI,MAAM,GAAyB,aAAa,CAAA;AAChD,sEAAsE;AACtE,MAAM,SAAS,GAAG,GAA2D,EAAE;IAC7E,IAAI,cAAc,KAAK,SAAS;QAAE,OAAO,cAAc,CAAA;IACvD,oGAAoG;IACpG,iGAAiG;IACjG,oGAAoG;IACpG,+FAA+F;IAC/F,qGAAqG;IACrG,oFAAoF;IACpF,MAAM,IAAI,GAAG,eA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AC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;YACzD,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;IAC9C,CAAC;IACD,qGAAqG;IACrG,wFAAwF;IACxF,aAAa;QACX,OAAO,EAAE,CAAA;IACX,CAAC;CACF,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nifrajs/web-svelte",
3
- "version": "5.0.0",
3
+ "version": "5.1.0",
4
4
  "description": "Svelte 5 render adapter for @nifrajs/web - SSR + hydration, with the .svelte compiler Bun plugin (@nifrajs/web-svelte/plugin).",
5
5
  "keywords": [
6
6
  "bun",
@@ -117,10 +117,10 @@
117
117
  "access": "public"
118
118
  },
119
119
  "dependencies": {
120
- "@nifrajs/core": "5.0.0",
121
- "@nifrajs/i18n": "5.0.0",
122
- "@nifrajs/image": "5.0.0",
123
- "@nifrajs/web": "5.0.0"
120
+ "@nifrajs/core": "5.1.0",
121
+ "@nifrajs/i18n": "5.1.0",
122
+ "@nifrajs/image": "5.1.0",
123
+ "@nifrajs/web": "5.1.0"
124
124
  },
125
125
  "peerDependencies": {
126
126
  "mdsvex": "^0.12",
package/src/index.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  * `.svelte` files, so this adapter ships a build plugin at `@nifrajs/web-svelte/plugin` (like
7
7
  * `@nifrajs/web-solid/plugin`) - there is no callable-component runtime.
8
8
  */
9
- import type { RenderAdapter, RenderProps } from "@nifrajs/web"
9
+ import type { RenderAdapter, RenderProps, RenderStreamOptions } from "@nifrajs/web"
10
10
  import { ssrModuleLoader } from "@nifrajs/web"
11
11
  import type { Component } from "svelte"
12
12
  import { render as runtimeRender } from "svelte/server"
@@ -91,31 +91,41 @@ function oneChunk(html: string): ReadableStream<Uint8Array> {
91
91
  })
92
92
  }
93
93
 
94
+ /** The body of one render; what `<svelte:head>` rendered goes into the document's `<head>`. */
95
+ function bodyOf(
96
+ Chain: Component<ChainProps>,
97
+ props: ChainProps,
98
+ options?: RenderStreamOptions,
99
+ ): string {
100
+ const out = render(Chain, { props })
101
+ if (options?.parts !== undefined) options.parts.head += out.head
102
+ return out.body
103
+ }
104
+
94
105
  /** The Svelte server render adapter - pass to @nifrajs/web's `renderPage`. */
95
106
  export const svelteAdapter: RenderAdapter = {
107
+ documentParts: true,
96
108
  // Svelte SSR is already synchronous + string-based, so this is the native shape: `renderToString`
97
109
  // returns the body directly (renderPage buffers it on the non-deferred fast path), and
98
110
  // `renderToStream` wraps the same string in a one-chunk stream for the deferred path. No streaming
99
111
  // renderer to skip here - but going straight to a string avoids the per-request stream allocation.
100
112
  // The seam allows `string | Promise<string>`, so the first render can resolve `Chain` while every
101
113
  // render after it stays a plain synchronous call - see `loadChain`.
102
- renderToString(chain, props) {
114
+ renderToString(chain, props, options) {
103
115
  const Chain = loadChain()
104
116
  const props$ = { chain, props, layoutData: props.layoutData }
105
117
  return Chain instanceof Promise
106
- ? Chain.then((C) => render(C, { props: props$ }).body)
107
- : render(Chain, { props: props$ }).body
118
+ ? Chain.then((C) => bodyOf(C, props$, options))
119
+ : bodyOf(Chain, props$, options)
108
120
  },
109
- renderToStream(chain, props) {
121
+ renderToStream(chain, props, options) {
110
122
  // `Chain` folds the layout chain (page innermost gets `props`; layouts wrap via their `children`
111
- // snippet). Svelte's `render` returns { head, body }; the body goes into #root. (Svelte's dynamic
112
- // `head` - from <svelte:head> - isn't surfaced through the seam's static `hydrationHead`; nifra's
113
- // own meta/head API manages the document head instead.)
123
+ // snippet). Svelte's `render` returns { head, body }; the body goes into #root.
114
124
  const Chain = loadChain()
115
125
  const props$ = { chain, props, layoutData: props.layoutData }
116
126
  return Chain instanceof Promise
117
- ? Chain.then((C) => oneChunk(render(C, { props: props$ }).body))
118
- : oneChunk(render(Chain, { props: props$ }).body)
127
+ ? Chain.then((C) => oneChunk(bodyOf(C, props$, options)))
128
+ : oneChunk(bodyOf(Chain, props$, options))
119
129
  },
120
130
  // Svelte's client `hydrate` reconciles against the existing DOM; no per-document bootstrap script is
121
131
  // needed (contrast Solid's generateHydrationScript) - the seam allows the empty string.