vike-react 0.6.9 → 0.6.11

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/dist/config.d.ts CHANGED
@@ -72,6 +72,20 @@ declare const config: {
72
72
  cumulative: true;
73
73
  global: true;
74
74
  };
75
+ headHtmlBegin: {
76
+ env: {
77
+ server: true;
78
+ };
79
+ cumulative: true;
80
+ global: true;
81
+ };
82
+ headHtmlEnd: {
83
+ env: {
84
+ server: true;
85
+ };
86
+ cumulative: true;
87
+ global: true;
88
+ };
75
89
  htmlAttributes: {
76
90
  env: {
77
91
  server: true;
package/dist/config.js CHANGED
@@ -60,6 +60,16 @@ const config = {
60
60
  cumulative: true,
61
61
  global: true,
62
62
  },
63
+ headHtmlBegin: {
64
+ env: { server: true },
65
+ cumulative: true,
66
+ global: true,
67
+ },
68
+ headHtmlEnd: {
69
+ env: { server: true },
70
+ cumulative: true,
71
+ global: true,
72
+ },
63
73
  htmlAttributes: {
64
74
  env: { server: true },
65
75
  global: true,
@@ -6,3 +6,4 @@ import type { PageContextInternal } from '../types/PageContext.js';
6
6
  declare function onRenderHtml(pageContext: PageContextServer & PageContextInternal): Promise<ReturnType<typeof escapeInject>>;
7
7
  export type PageHtmlStream = Awaited<ReturnType<typeof renderToStream>>;
8
8
  export type Viewport = 'responsive' | number | null;
9
+ export type HtmlInjection = string | ((pageContext: PageContextServer) => string);
@@ -19,7 +19,7 @@ addEcosystemStamp();
19
19
  async function onRenderHtml(pageContext) {
20
20
  await renderPageToHtml(pageContext);
21
21
  const headHtml = getHeadHtml(pageContext);
22
- const { bodyHtmlBegin, bodyHtmlEnd } = await getBodyHtmlBoundary(pageContext);
22
+ const { headHtmlBegin, headHtmlEnd, bodyHtmlBegin, bodyHtmlEnd } = await getHtmlInjections(pageContext);
23
23
  const { htmlAttributesString, bodyAttributesString } = getTagAttributes(pageContext);
24
24
  // Not needed on the client-side, thus we remove it to save KBs sent to the client
25
25
  delete pageContext._configFromHook;
@@ -39,7 +39,9 @@ async function onRenderHtml(pageContext) {
39
39
  <html${dangerouslySkipEscape(htmlAttributesString)}>
40
40
  <head>
41
41
  <meta charset="UTF-8" />
42
+ ${headHtmlBegin}
42
43
  ${headHtml}
44
+ ${headHtmlEnd}
43
45
  </head>
44
46
  <body${dangerouslySkipEscape(bodyAttributesString)}>
45
47
  ${bodyHtmlBegin}
@@ -175,10 +177,19 @@ function addEcosystemStamp() {
175
177
  // We use an object so that we can eventually, in the future, add helpful information as needed. (E.g. the vike-react version.)
176
178
  {};
177
179
  }
178
- async function getBodyHtmlBoundary(pageContext) {
179
- const bodyHtmlBegin = dangerouslySkipEscape((await callCumulativeHooks(pageContext.config.bodyHtmlBegin, pageContext)).join(''));
180
- const bodyHtmlEnd = dangerouslySkipEscape((await callCumulativeHooks(pageContext.config.bodyHtmlEnd, pageContext)).join(''));
181
- return { bodyHtmlBegin, bodyHtmlEnd };
180
+ async function getHtmlInjections(pageContext) {
181
+ const { config } = pageContext;
182
+ const renderHooks = async (hooks) => {
183
+ const values = await callCumulativeHooks(hooks, pageContext);
184
+ return dangerouslySkipEscape(values.join(''));
185
+ };
186
+ const [headHtmlBegin, headHtmlEnd, bodyHtmlBegin, bodyHtmlEnd] = await Promise.all([
187
+ renderHooks(config.headHtmlBegin),
188
+ renderHooks(config.headHtmlEnd),
189
+ renderHooks(config.bodyHtmlBegin),
190
+ renderHooks(config.bodyHtmlEnd),
191
+ ]);
192
+ return { bodyHtmlBegin, bodyHtmlEnd, headHtmlBegin, headHtmlEnd };
182
193
  }
183
194
  function resolveStreamSetting(pageContext) {
184
195
  const { stream,
@@ -1,6 +1,6 @@
1
1
  import type { ImportString, PageContext } from 'vike/types';
2
2
  import type { TagAttributes } from '../utils/getTagAttributesString.js';
3
- import type { Viewport } from '../integration/onRenderHtml.js';
3
+ import type { Viewport, HtmlInjection } from '../integration/onRenderHtml.js';
4
4
  import type { ConfigsCumulative } from '../hooks/useConfig/configsCumulative.js';
5
5
  import type React from 'react';
6
6
  import type { HydrationOptions, RootOptions } from 'react-dom/client';
@@ -110,13 +110,25 @@ declare global {
110
110
  *
111
111
  * https://vike.dev/bodyHtmlBegin
112
112
  */
113
- bodyHtmlBegin?: BodyHtmlBoundary;
113
+ bodyHtmlBegin?: HtmlInjection;
114
114
  /**
115
115
  * Raw HTML injected at the end of `<body>`.
116
116
  *
117
117
  * https://vike.dev/bodyHtmlEnd
118
118
  */
119
- bodyHtmlEnd?: BodyHtmlBoundary;
119
+ bodyHtmlEnd?: HtmlInjection;
120
+ /**
121
+ * Raw HTML injected at the start of `<head>`.
122
+ *
123
+ * https://vike.dev/headHtmlBegin
124
+ */
125
+ headHtmlBegin?: HtmlInjection;
126
+ /**
127
+ * Raw HTML injected at the end of `<head>`.
128
+ *
129
+ * https://vike.dev/headHtmlEnd
130
+ */
131
+ headHtmlEnd?: HtmlInjection;
120
132
  /**
121
133
  * Add tag attributes such as `<html class="dark">`.
122
134
  *
@@ -219,8 +231,10 @@ declare global {
219
231
  Wrapper?: Wrapper[];
220
232
  Layout?: Layout[];
221
233
  Head?: Head[];
222
- bodyHtmlBegin?: BodyHtmlBoundary[];
223
- bodyHtmlEnd?: BodyHtmlBoundary[];
234
+ bodyHtmlBegin?: HtmlInjection[];
235
+ bodyHtmlEnd?: HtmlInjection[];
236
+ headHtmlBegin?: HtmlInjection[];
237
+ headHtmlEnd?: HtmlInjection[];
224
238
  bodyAttributes?: TagAttributes[];
225
239
  htmlAttributes?: TagAttributes[];
226
240
  onBeforeRenderHtml?: Function[];
@@ -233,7 +247,6 @@ declare global {
233
247
  }
234
248
  }
235
249
  type PageContext_ = PageContext;
236
- type BodyHtmlBoundary = string | ((pageContext: PageContext) => string);
237
250
  export type Head = React.ReactNode | (() => React.ReactNode);
238
251
  type Wrapper = (props: {
239
252
  children: React.ReactNode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike-react",
3
- "version": "0.6.9",
3
+ "version": "0.6.11",
4
4
  "repository": "https://github.com/vikejs/vike-react",
5
5
  "type": "module",
6
6
  "exports": {
@@ -27,7 +27,7 @@
27
27
  "./__internal/integration/Loading": "./dist/integration/Loading.js"
28
28
  },
29
29
  "dependencies": {
30
- "react-streaming": "^0.4.10"
30
+ "react-streaming": "^0.4.11"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "react": ">=19",