vike 0.4.177-commit-51d612a → 0.4.178
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/cjs/node/runtime/html/injectAssets/getHtmlTags.js +3 -3
- package/dist/cjs/node/runtime/html/injectAssets/injectHtmlTags.js +20 -18
- package/dist/cjs/node/runtime/html/injectAssets.js +9 -9
- package/dist/cjs/node/runtime/html/renderHtml.js +4 -4
- package/dist/cjs/node/runtime/html/stream/react-streaming.js +11 -10
- package/dist/cjs/node/runtime/html/stream.js +5 -5
- package/dist/cjs/node/runtime/utils.js +1 -0
- package/dist/cjs/utils/isVikeReactApp.js +9 -0
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.d.ts +2 -2
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +3 -3
- package/dist/esm/node/runtime/html/injectAssets/injectHtmlTags.d.ts +5 -2
- package/dist/esm/node/runtime/html/injectAssets/injectHtmlTags.js +19 -17
- package/dist/esm/node/runtime/html/injectAssets.d.ts +2 -2
- package/dist/esm/node/runtime/html/injectAssets.js +10 -10
- package/dist/esm/node/runtime/html/renderHtml.js +5 -5
- package/dist/esm/node/runtime/html/stream/react-streaming.d.ts +16 -23
- package/dist/esm/node/runtime/html/stream/react-streaming.js +11 -10
- package/dist/esm/node/runtime/html/stream.d.ts +2 -2
- package/dist/esm/node/runtime/html/stream.js +6 -6
- package/dist/esm/node/runtime/utils.d.ts +1 -0
- package/dist/esm/node/runtime/utils.js +1 -0
- package/dist/esm/utils/isVikeReactApp.d.ts +1 -0
- package/dist/esm/utils/isVikeReactApp.js +5 -0
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +3 -3
|
@@ -12,7 +12,7 @@ const mergeScriptTags_js_1 = require("./mergeScriptTags.js");
|
|
|
12
12
|
const globalContext_js_1 = require("../../globalContext.js");
|
|
13
13
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
14
14
|
const stamp = '__injectFilterEntry';
|
|
15
|
-
function getHtmlTags(pageContext,
|
|
15
|
+
function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectFilter, pageAssets, viteDevScript) {
|
|
16
16
|
(0, utils_js_1.assert)([true, false].includes(pageContext._isHtmlOnly));
|
|
17
17
|
const isHtmlOnly = pageContext._isHtmlOnly;
|
|
18
18
|
const { isProduction } = (0, globalContext_js_1.getGlobalContext)();
|
|
@@ -88,11 +88,11 @@ function getHtmlTags(pageContext, injectToStream, injectFilter, pageAssets, vite
|
|
|
88
88
|
// See https://github.com/vikejs/vike/pull/1271
|
|
89
89
|
const positionJavaScriptEntry = (() => {
|
|
90
90
|
if (pageContext._pageContextPromise) {
|
|
91
|
-
(0, utils_js_1.assertWarning)(!
|
|
91
|
+
(0, utils_js_1.assertWarning)(!streamFromReactStreamingPackage, "[getHtmlTags()] We recommend against using streaming and a pageContext promise at the same time, because progressive hydration won't work.", { onlyOnce: true });
|
|
92
92
|
// If there is a pageContext._pageContextPromise (which is resolved after the stream has ended) then the pageContext JSON data needs to await for it: https://vike.dev/streaming#initial-data-after-stream-end
|
|
93
93
|
return 'HTML_END';
|
|
94
94
|
}
|
|
95
|
-
if (
|
|
95
|
+
if (streamFromReactStreamingPackage && !streamFromReactStreamingPackage.hasStreamEnded()) {
|
|
96
96
|
// If there is a stream then, in order to support progressive hydration, inject the JavaScript during the stream after React(/Vue/Solid/...) resolved the first suspense boundary
|
|
97
97
|
return 'STREAM';
|
|
98
98
|
}
|
|
@@ -1,23 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Unit tests at ./injectHtmlTags.spec.ts
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.injectAtClosingTag = exports.injectAtOpeningTag = exports.createHtmlHeadIfMissing = exports.injectHtmlTags = void 0;
|
|
4
|
+
exports.injectAtClosingTag = exports.injectAtOpeningTag = exports.createHtmlHeadIfMissing = exports.injectHtmlTagsUsingStream = exports.injectHtmlTags = void 0;
|
|
5
5
|
const utils_js_1 = require("../../utils.js");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
.map((h) => resolveHtmlTag(h.htmlTag))
|
|
12
|
-
.join('');
|
|
13
|
-
if (htmlFragment) {
|
|
14
|
-
htmlString = injectHtmlFragment(position, htmlFragment, htmlString, injectToStream);
|
|
15
|
-
}
|
|
16
|
-
});
|
|
6
|
+
function injectHtmlTags(htmlString, htmlTags, position) {
|
|
7
|
+
const htmlFragment = joinHtmlTags(htmlTags.filter((h) => h.position === position));
|
|
8
|
+
if (htmlFragment) {
|
|
9
|
+
htmlString = injectHtmlFragment(position, htmlFragment, htmlString);
|
|
10
|
+
}
|
|
17
11
|
return htmlString;
|
|
18
12
|
}
|
|
19
13
|
exports.injectHtmlTags = injectHtmlTags;
|
|
20
|
-
function
|
|
14
|
+
async function injectHtmlTagsUsingStream(htmlTags, streamFromReactStreamingPackage) {
|
|
15
|
+
const htmlFragment = joinHtmlTags(htmlTags.filter((h) => h.position === 'STREAM'));
|
|
16
|
+
if (htmlFragment) {
|
|
17
|
+
(0, utils_js_1.assert)(streamFromReactStreamingPackage);
|
|
18
|
+
(0, utils_js_1.assert)(!streamFromReactStreamingPackage.hasStreamEnded());
|
|
19
|
+
await streamFromReactStreamingPackage.injectToStream(htmlFragment, { flush: true });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.injectHtmlTagsUsingStream = injectHtmlTagsUsingStream;
|
|
23
|
+
function joinHtmlTags(htmlTags) {
|
|
24
|
+
const htmlFragment = htmlTags.map((h) => resolveHtmlTag(h.htmlTag)).join('');
|
|
25
|
+
return htmlFragment;
|
|
26
|
+
}
|
|
27
|
+
function injectHtmlFragment(position, htmlFragment, htmlString) {
|
|
21
28
|
if (position === 'HTML_BEGIN') {
|
|
22
29
|
{
|
|
23
30
|
const res = injectAtPaceholder(htmlFragment, htmlString, true);
|
|
@@ -42,11 +49,6 @@ function injectHtmlFragment(position, htmlFragment, htmlString, injectToStream)
|
|
|
42
49
|
}
|
|
43
50
|
return htmlString + '\n' + htmlFragment;
|
|
44
51
|
}
|
|
45
|
-
if (position === 'STREAM') {
|
|
46
|
-
(0, utils_js_1.assert)(injectToStream);
|
|
47
|
-
injectToStream(htmlFragment, { flush: true });
|
|
48
|
-
return htmlString;
|
|
49
|
-
}
|
|
50
52
|
(0, utils_js_1.assert)(false);
|
|
51
53
|
}
|
|
52
54
|
function resolveHtmlTag(htmlTag) {
|
|
@@ -11,12 +11,13 @@ async function injectHtmlTagsToString(htmlParts, pageContext, injectFilter) {
|
|
|
11
11
|
const viteDevScript = await (0, getViteDevScript_js_1.getViteDevScript)();
|
|
12
12
|
const htmlTags = (0, getHtmlTags_js_1.getHtmlTags)(pageContext, null, injectFilter, pageAssets, viteDevScript);
|
|
13
13
|
let htmlString = htmlPartsToString(htmlParts, pageAssets);
|
|
14
|
-
htmlString = injectToHtmlBegin(htmlString, htmlTags
|
|
14
|
+
htmlString = injectToHtmlBegin(htmlString, htmlTags);
|
|
15
15
|
htmlString = injectToHtmlEnd(htmlString, htmlTags);
|
|
16
|
+
(0, utils_js_1.assert)(htmlTags.filter((snippet) => snippet.position === 'STREAM').length === 0);
|
|
16
17
|
return htmlString;
|
|
17
18
|
}
|
|
18
19
|
exports.injectHtmlTagsToString = injectHtmlTagsToString;
|
|
19
|
-
function injectHtmlTagsToStream(pageContext,
|
|
20
|
+
function injectHtmlTagsToStream(pageContext, streamFromReactStreamingPackage, injectFilter) {
|
|
20
21
|
let htmlTags;
|
|
21
22
|
return {
|
|
22
23
|
injectAtStreamBegin,
|
|
@@ -25,9 +26,10 @@ function injectHtmlTagsToStream(pageContext, injectToStream, injectFilter) {
|
|
|
25
26
|
async function injectAtStreamBegin(htmlPartsBegin) {
|
|
26
27
|
const pageAssets = await pageContext.__getPageAssets();
|
|
27
28
|
const viteDevScript = await (0, getViteDevScript_js_1.getViteDevScript)();
|
|
28
|
-
htmlTags = (0, getHtmlTags_js_1.getHtmlTags)(pageContext,
|
|
29
|
+
htmlTags = (0, getHtmlTags_js_1.getHtmlTags)(pageContext, streamFromReactStreamingPackage, injectFilter, pageAssets, viteDevScript);
|
|
29
30
|
let htmlBegin = htmlPartsToString(htmlPartsBegin, pageAssets);
|
|
30
|
-
htmlBegin = injectToHtmlBegin(htmlBegin, htmlTags
|
|
31
|
+
htmlBegin = injectToHtmlBegin(htmlBegin, htmlTags);
|
|
32
|
+
await (0, injectHtmlTags_js_1.injectHtmlTagsUsingStream)(htmlTags, streamFromReactStreamingPackage);
|
|
31
33
|
return htmlBegin;
|
|
32
34
|
}
|
|
33
35
|
async function injectAtStreamEnd(htmlPartsEnd) {
|
|
@@ -40,16 +42,14 @@ function injectHtmlTagsToStream(pageContext, injectToStream, injectFilter) {
|
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
44
|
exports.injectHtmlTagsToStream = injectHtmlTagsToStream;
|
|
43
|
-
function injectToHtmlBegin(htmlBegin, htmlTags
|
|
44
|
-
const htmlTagsAtBegin = htmlTags.filter((snippet) => snippet.position !== 'HTML_END');
|
|
45
|
+
function injectToHtmlBegin(htmlBegin, htmlTags) {
|
|
45
46
|
// Ensure existence of `<head>`
|
|
46
47
|
htmlBegin = (0, injectHtmlTags_js_1.createHtmlHeadIfMissing)(htmlBegin);
|
|
47
|
-
htmlBegin = (0, injectHtmlTags_js_1.injectHtmlTags)(htmlBegin,
|
|
48
|
+
htmlBegin = (0, injectHtmlTags_js_1.injectHtmlTags)(htmlBegin, htmlTags, 'HTML_BEGIN');
|
|
48
49
|
return htmlBegin;
|
|
49
50
|
}
|
|
50
51
|
function injectToHtmlEnd(htmlEnd, htmlTags) {
|
|
51
|
-
|
|
52
|
-
htmlEnd = (0, injectHtmlTags_js_1.injectHtmlTags)(htmlEnd, htmlTagsAtEnd, null);
|
|
52
|
+
htmlEnd = (0, injectHtmlTags_js_1.injectHtmlTags)(htmlEnd, htmlTags, 'HTML_END');
|
|
53
53
|
return htmlEnd;
|
|
54
54
|
}
|
|
55
55
|
async function resolvePageContextPromise(pageContext) {
|
|
@@ -60,11 +60,11 @@ async function renderHtmlStream(streamOriginal, injectString, pageContext, onErr
|
|
|
60
60
|
enableEagerStreaming: pageContext.enableEagerStreaming
|
|
61
61
|
};
|
|
62
62
|
if (injectString) {
|
|
63
|
-
let
|
|
64
|
-
if ((0, react_streaming_js_1.
|
|
65
|
-
|
|
63
|
+
let streamFromReactStreamingPackage = null;
|
|
64
|
+
if ((0, react_streaming_js_1.isStreamFromReactStreamingPackage)(streamOriginal) && !streamOriginal.disabled) {
|
|
65
|
+
streamFromReactStreamingPackage = streamOriginal;
|
|
66
66
|
}
|
|
67
|
-
const { injectAtStreamBegin, injectAtStreamEnd } = (0, injectAssets_js_1.injectHtmlTagsToStream)(pageContext,
|
|
67
|
+
const { injectAtStreamBegin, injectAtStreamEnd } = (0, injectAssets_js_1.injectHtmlTagsToStream)(pageContext, streamFromReactStreamingPackage, injectFilter);
|
|
68
68
|
(0, utils_js_1.objectAssign)(opts, {
|
|
69
69
|
injectStringAtBegin: async () => {
|
|
70
70
|
return await injectAtStreamBegin(injectString.htmlPartsBegin);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Zero-config support for https://www.npmjs.com/package/react-streaming
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
4
|
+
exports.getStreamOfReactStreamingPackage = exports.streamFromReactStreamingPackageToString = exports.isStreamFromReactStreamingPackage = void 0;
|
|
5
5
|
const utils_js_1 = require("../../utils.js");
|
|
6
6
|
const stream_js_1 = require("../stream.js");
|
|
7
|
-
function
|
|
7
|
+
function streamFromReactStreamingPackageToString(stream) {
|
|
8
8
|
if (stream.pipe) {
|
|
9
9
|
return (0, stream_js_1.streamPipeNodeToString)(stream.pipe);
|
|
10
10
|
}
|
|
@@ -13,19 +13,20 @@ function streamReactStreamingToString(stream) {
|
|
|
13
13
|
}
|
|
14
14
|
(0, utils_js_1.assert)(false);
|
|
15
15
|
}
|
|
16
|
-
exports.
|
|
17
|
-
function
|
|
16
|
+
exports.streamFromReactStreamingPackageToString = streamFromReactStreamingPackageToString;
|
|
17
|
+
function isStreamFromReactStreamingPackage(thing) {
|
|
18
18
|
if ((0, utils_js_1.hasProp)(thing, 'injectToStream', 'function')) {
|
|
19
|
+
(0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(thing, 'hasStreamEnded', 'function'), (0, utils_js_1.isVikeReactApp)()
|
|
20
|
+
? //
|
|
21
|
+
'Update vike-react to its latest version'
|
|
22
|
+
: 'Update react-streaming to its latest version');
|
|
19
23
|
return true;
|
|
20
24
|
}
|
|
21
|
-
// TODO
|
|
22
|
-
//if( isStreamPipeNode
|
|
23
25
|
return false;
|
|
24
26
|
}
|
|
25
|
-
exports.
|
|
26
|
-
function
|
|
27
|
+
exports.isStreamFromReactStreamingPackage = isStreamFromReactStreamingPackage;
|
|
28
|
+
function getStreamOfReactStreamingPackage(stream) {
|
|
27
29
|
if (stream.pipe) {
|
|
28
|
-
// TODO
|
|
29
30
|
return { __streamPipeNode: stream.pipe };
|
|
30
31
|
}
|
|
31
32
|
if (stream.readable) {
|
|
@@ -33,4 +34,4 @@ function getStreamFromReactStreaming(stream) {
|
|
|
33
34
|
}
|
|
34
35
|
(0, utils_js_1.assert)(false);
|
|
35
36
|
}
|
|
36
|
-
exports.
|
|
37
|
+
exports.getStreamOfReactStreamingPackage = getStreamOfReactStreamingPackage;
|
|
@@ -354,9 +354,9 @@ async function processStream(streamOriginal, { injectStringAtBegin, injectString
|
|
|
354
354
|
}
|
|
355
355
|
exports.processStream = processStream;
|
|
356
356
|
async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onFlush, onReadyToWrite }) {
|
|
357
|
-
if ((0, react_streaming_js_1.
|
|
357
|
+
if ((0, react_streaming_js_1.isStreamFromReactStreamingPackage)(streamOriginal)) {
|
|
358
358
|
debug(`onRenderHtml() hook returned ${picocolors_1.default.cyan('react-streaming')} result`);
|
|
359
|
-
const stream = (0, react_streaming_js_1.
|
|
359
|
+
const stream = (0, react_streaming_js_1.getStreamOfReactStreamingPackage)(streamOriginal);
|
|
360
360
|
streamOriginal = stream;
|
|
361
361
|
}
|
|
362
362
|
if (isStreamPipeNode(streamOriginal)) {
|
|
@@ -621,7 +621,7 @@ function isStream(something) {
|
|
|
621
621
|
isStreamReadableNode(something) ||
|
|
622
622
|
isStreamPipeNode(something) ||
|
|
623
623
|
isStreamPipeWeb(something) ||
|
|
624
|
-
(0, react_streaming_js_1.
|
|
624
|
+
(0, react_streaming_js_1.isStreamFromReactStreamingPackage)(something)) {
|
|
625
625
|
(0, utils_js_1.checkType)(something);
|
|
626
626
|
return true;
|
|
627
627
|
}
|
|
@@ -733,8 +733,8 @@ async function streamToString(stream) {
|
|
|
733
733
|
if (isStreamPipeWeb(stream)) {
|
|
734
734
|
return await streamPipeWebToString(getStreamPipeWeb(stream));
|
|
735
735
|
}
|
|
736
|
-
if ((0, react_streaming_js_1.
|
|
737
|
-
return await (0, react_streaming_js_1.
|
|
736
|
+
if ((0, react_streaming_js_1.isStreamFromReactStreamingPackage)(stream)) {
|
|
737
|
+
return await (0, react_streaming_js_1.streamFromReactStreamingPackageToString)(stream);
|
|
738
738
|
}
|
|
739
739
|
(0, utils_js_1.assert)(false);
|
|
740
740
|
}
|
|
@@ -70,3 +70,4 @@ __exportStar(require("../../utils/joinEnglish.js"), exports);
|
|
|
70
70
|
__exportStar(require("../../utils/isArrayOfStrings.js"), exports);
|
|
71
71
|
__exportStar(require("../../utils/escapeHtml.js"), exports);
|
|
72
72
|
__exportStar(require("../../utils/normalizeHeaders.js"), exports);
|
|
73
|
+
__exportStar(require("../../utils/isVikeReactApp.js"), exports);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isVikeReactApp = void 0;
|
|
4
|
+
function isVikeReactApp() {
|
|
5
|
+
const g = globalThis;
|
|
6
|
+
// Set by vike-react https://github.com/vikejs/vike-react/blob/23e92434424f10e7e742b6bf587edee5aa8832df/packages/vike-react/src/renderer/onRenderHtml.tsx#L75
|
|
7
|
+
return !!g._isVikeReactApp;
|
|
8
|
+
}
|
|
9
|
+
exports.isVikeReactApp = isVikeReactApp;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PROJECT_VERSION = exports.projectInfo = void 0;
|
|
4
|
-
const PROJECT_VERSION = '0.4.
|
|
4
|
+
const PROJECT_VERSION = '0.4.178';
|
|
5
5
|
exports.PROJECT_VERSION = PROJECT_VERSION;
|
|
6
6
|
const projectInfo = {
|
|
7
7
|
projectName: 'Vike',
|
|
@@ -3,7 +3,7 @@ export type { HtmlTag };
|
|
|
3
3
|
export type { PreloadFilter };
|
|
4
4
|
export type { InjectFilterEntry };
|
|
5
5
|
import type { PageContextInjectAssets } from '../injectAssets.js';
|
|
6
|
-
import type {
|
|
6
|
+
import type { StreamFromReactStreamingPackage } from '../stream/react-streaming.js';
|
|
7
7
|
import type { PageAsset } from '../../renderPage/getPageAssets.js';
|
|
8
8
|
type PreloadFilter = null | ((assets: InjectFilterEntry[]) => InjectFilterEntry[]);
|
|
9
9
|
type PreloadFilterInject = false | 'HTML_BEGIN' | 'HTML_END';
|
|
@@ -28,4 +28,4 @@ type HtmlTag = {
|
|
|
28
28
|
};
|
|
29
29
|
declare function getHtmlTags(pageContext: {
|
|
30
30
|
_isStream: boolean;
|
|
31
|
-
} & PageContextInjectAssets,
|
|
31
|
+
} & PageContextInjectAssets, streamFromReactStreamingPackage: null | StreamFromReactStreamingPackage, injectFilter: PreloadFilter, pageAssets: PageAsset[], viteDevScript: string): HtmlTag[];
|
|
@@ -7,7 +7,7 @@ import { mergeScriptTags } from './mergeScriptTags.js';
|
|
|
7
7
|
import { getGlobalContext } from '../../globalContext.js';
|
|
8
8
|
import pc from '@brillout/picocolors';
|
|
9
9
|
const stamp = '__injectFilterEntry';
|
|
10
|
-
function getHtmlTags(pageContext,
|
|
10
|
+
function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectFilter, pageAssets, viteDevScript) {
|
|
11
11
|
assert([true, false].includes(pageContext._isHtmlOnly));
|
|
12
12
|
const isHtmlOnly = pageContext._isHtmlOnly;
|
|
13
13
|
const { isProduction } = getGlobalContext();
|
|
@@ -83,11 +83,11 @@ function getHtmlTags(pageContext, injectToStream, injectFilter, pageAssets, vite
|
|
|
83
83
|
// See https://github.com/vikejs/vike/pull/1271
|
|
84
84
|
const positionJavaScriptEntry = (() => {
|
|
85
85
|
if (pageContext._pageContextPromise) {
|
|
86
|
-
assertWarning(!
|
|
86
|
+
assertWarning(!streamFromReactStreamingPackage, "[getHtmlTags()] We recommend against using streaming and a pageContext promise at the same time, because progressive hydration won't work.", { onlyOnce: true });
|
|
87
87
|
// If there is a pageContext._pageContextPromise (which is resolved after the stream has ended) then the pageContext JSON data needs to await for it: https://vike.dev/streaming#initial-data-after-stream-end
|
|
88
88
|
return 'HTML_END';
|
|
89
89
|
}
|
|
90
|
-
if (
|
|
90
|
+
if (streamFromReactStreamingPackage && !streamFromReactStreamingPackage.hasStreamEnded()) {
|
|
91
91
|
// If there is a stream then, in order to support progressive hydration, inject the JavaScript during the stream after React(/Vue/Solid/...) resolved the first suspense boundary
|
|
92
92
|
return 'STREAM';
|
|
93
93
|
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
export { injectHtmlTags };
|
|
2
|
+
export { injectHtmlTagsUsingStream };
|
|
2
3
|
export { createHtmlHeadIfMissing };
|
|
3
4
|
export { injectAtOpeningTag };
|
|
4
5
|
export { injectAtClosingTag };
|
|
6
|
+
import type { StreamFromReactStreamingPackage } from '../stream/react-streaming.js';
|
|
5
7
|
import type { HtmlTag } from './getHtmlTags.js';
|
|
6
|
-
|
|
7
|
-
declare function injectHtmlTags(htmlString: string, htmlTags: HtmlTag[],
|
|
8
|
+
type Position = 'HTML_BEGIN' | 'HTML_END';
|
|
9
|
+
declare function injectHtmlTags(htmlString: string, htmlTags: HtmlTag[], position: Position): string;
|
|
10
|
+
declare function injectHtmlTagsUsingStream(htmlTags: HtmlTag[], streamFromReactStreamingPackage: null | StreamFromReactStreamingPackage): Promise<void>;
|
|
8
11
|
declare function injectAtOpeningTag(tag: 'head' | 'html' | '!doctype', htmlString: string, htmlFragment: string): string;
|
|
9
12
|
declare function injectAtClosingTag(tag: 'body' | 'html', htmlString: string, htmlFragment: string): string;
|
|
10
13
|
declare function createHtmlHeadIfMissing(htmlString: string): string;
|
|
@@ -1,24 +1,31 @@
|
|
|
1
1
|
// Unit tests at ./injectHtmlTags.spec.ts
|
|
2
2
|
export { injectHtmlTags };
|
|
3
|
+
export { injectHtmlTagsUsingStream };
|
|
3
4
|
export { createHtmlHeadIfMissing };
|
|
4
5
|
// Only needed for unit tests
|
|
5
6
|
export { injectAtOpeningTag };
|
|
6
7
|
export { injectAtClosingTag };
|
|
7
8
|
import { assert, assertUsage, slice } from '../../utils.js';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
.map((h) => resolveHtmlTag(h.htmlTag))
|
|
14
|
-
.join('');
|
|
15
|
-
if (htmlFragment) {
|
|
16
|
-
htmlString = injectHtmlFragment(position, htmlFragment, htmlString, injectToStream);
|
|
17
|
-
}
|
|
18
|
-
});
|
|
9
|
+
function injectHtmlTags(htmlString, htmlTags, position) {
|
|
10
|
+
const htmlFragment = joinHtmlTags(htmlTags.filter((h) => h.position === position));
|
|
11
|
+
if (htmlFragment) {
|
|
12
|
+
htmlString = injectHtmlFragment(position, htmlFragment, htmlString);
|
|
13
|
+
}
|
|
19
14
|
return htmlString;
|
|
20
15
|
}
|
|
21
|
-
function
|
|
16
|
+
async function injectHtmlTagsUsingStream(htmlTags, streamFromReactStreamingPackage) {
|
|
17
|
+
const htmlFragment = joinHtmlTags(htmlTags.filter((h) => h.position === 'STREAM'));
|
|
18
|
+
if (htmlFragment) {
|
|
19
|
+
assert(streamFromReactStreamingPackage);
|
|
20
|
+
assert(!streamFromReactStreamingPackage.hasStreamEnded());
|
|
21
|
+
await streamFromReactStreamingPackage.injectToStream(htmlFragment, { flush: true });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function joinHtmlTags(htmlTags) {
|
|
25
|
+
const htmlFragment = htmlTags.map((h) => resolveHtmlTag(h.htmlTag)).join('');
|
|
26
|
+
return htmlFragment;
|
|
27
|
+
}
|
|
28
|
+
function injectHtmlFragment(position, htmlFragment, htmlString) {
|
|
22
29
|
if (position === 'HTML_BEGIN') {
|
|
23
30
|
{
|
|
24
31
|
const res = injectAtPaceholder(htmlFragment, htmlString, true);
|
|
@@ -43,11 +50,6 @@ function injectHtmlFragment(position, htmlFragment, htmlString, injectToStream)
|
|
|
43
50
|
}
|
|
44
51
|
return htmlString + '\n' + htmlFragment;
|
|
45
52
|
}
|
|
46
|
-
if (position === 'STREAM') {
|
|
47
|
-
assert(injectToStream);
|
|
48
|
-
injectToStream(htmlFragment, { flush: true });
|
|
49
|
-
return htmlString;
|
|
50
|
-
}
|
|
51
53
|
assert(false);
|
|
52
54
|
}
|
|
53
55
|
function resolveHtmlTag(htmlTag) {
|
|
@@ -5,7 +5,7 @@ export type { PageContextPromise };
|
|
|
5
5
|
import type { PageAsset } from '../renderPage/getPageAssets.js';
|
|
6
6
|
import type { HtmlPart } from './renderHtml.js';
|
|
7
7
|
import { type PreloadFilter } from './injectAssets/getHtmlTags.js';
|
|
8
|
-
import type {
|
|
8
|
+
import type { StreamFromReactStreamingPackage } from './stream/react-streaming.js';
|
|
9
9
|
import type { PageConfigRuntime } from '../../../shared/page-configs/PageConfig.js';
|
|
10
10
|
import type { PageContextSerialization } from './serializePageContextClientSide.js';
|
|
11
11
|
type PageContextInjectAssets = {
|
|
@@ -27,7 +27,7 @@ declare function injectHtmlTagsToString(htmlParts: HtmlPart[], pageContext: Page
|
|
|
27
27
|
}, injectFilter: PreloadFilter): Promise<string>;
|
|
28
28
|
declare function injectHtmlTagsToStream(pageContext: PageContextInjectAssets & {
|
|
29
29
|
_isStream: true;
|
|
30
|
-
},
|
|
30
|
+
}, streamFromReactStreamingPackage: null | StreamFromReactStreamingPackage, injectFilter: PreloadFilter): {
|
|
31
31
|
injectAtStreamBegin: (htmlPartsBegin: HtmlPart[]) => Promise<string>;
|
|
32
32
|
injectAtStreamEnd: (htmlPartsEnd: HtmlPart[]) => Promise<string>;
|
|
33
33
|
};
|
|
@@ -2,7 +2,7 @@ export { injectHtmlTagsToString };
|
|
|
2
2
|
export { injectHtmlTagsToStream };
|
|
3
3
|
import { assert, isCallable, isPromise } from '../utils.js';
|
|
4
4
|
import { assertPageContextProvidedByUser } from '../../../shared/assertPageContextProvidedByUser.js';
|
|
5
|
-
import { injectHtmlTags, createHtmlHeadIfMissing } from './injectAssets/injectHtmlTags.js';
|
|
5
|
+
import { injectHtmlTags, createHtmlHeadIfMissing, injectHtmlTagsUsingStream } from './injectAssets/injectHtmlTags.js';
|
|
6
6
|
import { getHtmlTags } from './injectAssets/getHtmlTags.js';
|
|
7
7
|
import { getViteDevScript } from './injectAssets/getViteDevScript.js';
|
|
8
8
|
async function injectHtmlTagsToString(htmlParts, pageContext, injectFilter) {
|
|
@@ -10,11 +10,12 @@ async function injectHtmlTagsToString(htmlParts, pageContext, injectFilter) {
|
|
|
10
10
|
const viteDevScript = await getViteDevScript();
|
|
11
11
|
const htmlTags = getHtmlTags(pageContext, null, injectFilter, pageAssets, viteDevScript);
|
|
12
12
|
let htmlString = htmlPartsToString(htmlParts, pageAssets);
|
|
13
|
-
htmlString = injectToHtmlBegin(htmlString, htmlTags
|
|
13
|
+
htmlString = injectToHtmlBegin(htmlString, htmlTags);
|
|
14
14
|
htmlString = injectToHtmlEnd(htmlString, htmlTags);
|
|
15
|
+
assert(htmlTags.filter((snippet) => snippet.position === 'STREAM').length === 0);
|
|
15
16
|
return htmlString;
|
|
16
17
|
}
|
|
17
|
-
function injectHtmlTagsToStream(pageContext,
|
|
18
|
+
function injectHtmlTagsToStream(pageContext, streamFromReactStreamingPackage, injectFilter) {
|
|
18
19
|
let htmlTags;
|
|
19
20
|
return {
|
|
20
21
|
injectAtStreamBegin,
|
|
@@ -23,9 +24,10 @@ function injectHtmlTagsToStream(pageContext, injectToStream, injectFilter) {
|
|
|
23
24
|
async function injectAtStreamBegin(htmlPartsBegin) {
|
|
24
25
|
const pageAssets = await pageContext.__getPageAssets();
|
|
25
26
|
const viteDevScript = await getViteDevScript();
|
|
26
|
-
htmlTags = getHtmlTags(pageContext,
|
|
27
|
+
htmlTags = getHtmlTags(pageContext, streamFromReactStreamingPackage, injectFilter, pageAssets, viteDevScript);
|
|
27
28
|
let htmlBegin = htmlPartsToString(htmlPartsBegin, pageAssets);
|
|
28
|
-
htmlBegin = injectToHtmlBegin(htmlBegin, htmlTags
|
|
29
|
+
htmlBegin = injectToHtmlBegin(htmlBegin, htmlTags);
|
|
30
|
+
await injectHtmlTagsUsingStream(htmlTags, streamFromReactStreamingPackage);
|
|
29
31
|
return htmlBegin;
|
|
30
32
|
}
|
|
31
33
|
async function injectAtStreamEnd(htmlPartsEnd) {
|
|
@@ -37,16 +39,14 @@ function injectHtmlTagsToStream(pageContext, injectToStream, injectFilter) {
|
|
|
37
39
|
return htmlEnd;
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
|
-
function injectToHtmlBegin(htmlBegin, htmlTags
|
|
41
|
-
const htmlTagsAtBegin = htmlTags.filter((snippet) => snippet.position !== 'HTML_END');
|
|
42
|
+
function injectToHtmlBegin(htmlBegin, htmlTags) {
|
|
42
43
|
// Ensure existence of `<head>`
|
|
43
44
|
htmlBegin = createHtmlHeadIfMissing(htmlBegin);
|
|
44
|
-
htmlBegin = injectHtmlTags(htmlBegin,
|
|
45
|
+
htmlBegin = injectHtmlTags(htmlBegin, htmlTags, 'HTML_BEGIN');
|
|
45
46
|
return htmlBegin;
|
|
46
47
|
}
|
|
47
48
|
function injectToHtmlEnd(htmlEnd, htmlTags) {
|
|
48
|
-
|
|
49
|
-
htmlEnd = injectHtmlTags(htmlEnd, htmlTagsAtEnd, null);
|
|
49
|
+
htmlEnd = injectHtmlTags(htmlEnd, htmlTags, 'HTML_END');
|
|
50
50
|
return htmlEnd;
|
|
51
51
|
}
|
|
52
52
|
async function resolvePageContextPromise(pageContext) {
|
|
@@ -6,7 +6,7 @@ export { getHtmlString };
|
|
|
6
6
|
import { assert, assertUsage, assertWarning, checkType, escapeHtml, hasProp, isHtml, isPromise, objectAssign } from '../utils.js';
|
|
7
7
|
import { injectHtmlTagsToString, injectHtmlTagsToStream } from './injectAssets.js';
|
|
8
8
|
import { processStream, isStream, streamToString } from './stream.js';
|
|
9
|
-
import {
|
|
9
|
+
import { isStreamFromReactStreamingPackage } from './stream/react-streaming.js';
|
|
10
10
|
import { getGlobalContext } from '../globalContext.js';
|
|
11
11
|
import pc from '@brillout/picocolors';
|
|
12
12
|
function isDocumentHtml(something) {
|
|
@@ -57,11 +57,11 @@ async function renderHtmlStream(streamOriginal, injectString, pageContext, onErr
|
|
|
57
57
|
enableEagerStreaming: pageContext.enableEagerStreaming
|
|
58
58
|
};
|
|
59
59
|
if (injectString) {
|
|
60
|
-
let
|
|
61
|
-
if (
|
|
62
|
-
|
|
60
|
+
let streamFromReactStreamingPackage = null;
|
|
61
|
+
if (isStreamFromReactStreamingPackage(streamOriginal) && !streamOriginal.disabled) {
|
|
62
|
+
streamFromReactStreamingPackage = streamOriginal;
|
|
63
63
|
}
|
|
64
|
-
const { injectAtStreamBegin, injectAtStreamEnd } = injectHtmlTagsToStream(pageContext,
|
|
64
|
+
const { injectAtStreamBegin, injectAtStreamEnd } = injectHtmlTagsToStream(pageContext, streamFromReactStreamingPackage, injectFilter);
|
|
65
65
|
objectAssign(opts, {
|
|
66
66
|
injectStringAtBegin: async () => {
|
|
67
67
|
return await injectAtStreamBegin(injectString.htmlPartsBegin);
|
|
@@ -1,25 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export type {
|
|
6
|
-
|
|
1
|
+
export { isStreamFromReactStreamingPackage };
|
|
2
|
+
export { streamFromReactStreamingPackageToString };
|
|
3
|
+
export { getStreamOfReactStreamingPackage };
|
|
4
|
+
export type { StreamFromReactStreamingPackage };
|
|
5
|
+
export type { StreamFromReactStreamingPackagePublic };
|
|
6
|
+
import type { renderToStream } from 'react-streaming/server';
|
|
7
7
|
import { StreamReadableWeb, StreamWritableNode } from '../stream.js';
|
|
8
|
-
type
|
|
9
|
-
|
|
10
|
-
}) => void;
|
|
11
|
-
type StreamReactStreaming = {
|
|
12
|
-
injectToStream: InjectToStream;
|
|
13
|
-
disabled?: boolean;
|
|
14
|
-
} & ({
|
|
15
|
-
pipe: (writable: StreamWritableNode) => void;
|
|
16
|
-
readable: null;
|
|
17
|
-
} | {
|
|
18
|
-
pipe: null;
|
|
19
|
-
readable: StreamReadableWeb;
|
|
20
|
-
});
|
|
21
|
-
declare function streamReactStreamingToString(stream: StreamReactStreaming): Promise<string>;
|
|
22
|
-
declare function isStreamReactStreaming(thing: unknown): thing is StreamReactStreaming;
|
|
23
|
-
declare function getStreamFromReactStreaming(stream: StreamReactStreaming): StreamReadableWeb | {
|
|
24
|
-
__streamPipeNode: (writable: import("stream").Writable) => void;
|
|
8
|
+
type StreamFromReactStreamingPackagePublic = {
|
|
9
|
+
injectToStream: Function;
|
|
25
10
|
};
|
|
11
|
+
type StreamFromReactStreamingPackage = Awaited<ReturnType<typeof renderToStream>>;
|
|
12
|
+
declare function streamFromReactStreamingPackageToString(stream: StreamFromReactStreamingPackage): Promise<string>;
|
|
13
|
+
declare function isStreamFromReactStreamingPackage(thing: unknown): thing is StreamFromReactStreamingPackage;
|
|
14
|
+
type Pipe = {
|
|
15
|
+
__streamPipeNode: (writable: StreamWritableNode) => void;
|
|
16
|
+
};
|
|
17
|
+
type Readable = StreamReadableWeb;
|
|
18
|
+
declare function getStreamOfReactStreamingPackage(stream: StreamFromReactStreamingPackage): Pipe | Readable;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// Zero-config support for https://www.npmjs.com/package/react-streaming
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
import { assert, hasProp } from '../../utils.js';
|
|
2
|
+
export { isStreamFromReactStreamingPackage };
|
|
3
|
+
export { streamFromReactStreamingPackageToString };
|
|
4
|
+
export { getStreamOfReactStreamingPackage };
|
|
5
|
+
import { assert, assertUsage, hasProp, isVikeReactApp } from '../../utils.js';
|
|
6
6
|
import { streamPipeNodeToString, streamReadableWebToString } from '../stream.js';
|
|
7
|
-
function
|
|
7
|
+
function streamFromReactStreamingPackageToString(stream) {
|
|
8
8
|
if (stream.pipe) {
|
|
9
9
|
return streamPipeNodeToString(stream.pipe);
|
|
10
10
|
}
|
|
@@ -13,17 +13,18 @@ function streamReactStreamingToString(stream) {
|
|
|
13
13
|
}
|
|
14
14
|
assert(false);
|
|
15
15
|
}
|
|
16
|
-
function
|
|
16
|
+
function isStreamFromReactStreamingPackage(thing) {
|
|
17
17
|
if (hasProp(thing, 'injectToStream', 'function')) {
|
|
18
|
+
assertUsage(hasProp(thing, 'hasStreamEnded', 'function'), isVikeReactApp()
|
|
19
|
+
? //
|
|
20
|
+
'Update vike-react to its latest version'
|
|
21
|
+
: 'Update react-streaming to its latest version');
|
|
18
22
|
return true;
|
|
19
23
|
}
|
|
20
|
-
// TODO
|
|
21
|
-
//if( isStreamPipeNode
|
|
22
24
|
return false;
|
|
23
25
|
}
|
|
24
|
-
function
|
|
26
|
+
function getStreamOfReactStreamingPackage(stream) {
|
|
25
27
|
if (stream.pipe) {
|
|
26
|
-
// TODO
|
|
27
28
|
return { __streamPipeNode: stream.pipe };
|
|
28
29
|
}
|
|
29
30
|
if (stream.readable) {
|
|
@@ -30,7 +30,7 @@ export type { StreamWritableNode };
|
|
|
30
30
|
export type { StreamPipeWeb };
|
|
31
31
|
export type { StreamPipeNode };
|
|
32
32
|
import { HtmlRender } from './renderHtml.js';
|
|
33
|
-
import {
|
|
33
|
+
import { StreamFromReactStreamingPackagePublic } from './stream/react-streaming.js';
|
|
34
34
|
import type { Readable as Readable_, Writable as Writable_ } from 'node:stream';
|
|
35
35
|
type StreamReadableWeb = ReadableStream;
|
|
36
36
|
type StreamReadableNode = Readable_;
|
|
@@ -39,7 +39,7 @@ type StreamWritableNode = Writable_;
|
|
|
39
39
|
type StreamPipeWeb = (writable: StreamWritableWeb) => void;
|
|
40
40
|
type StreamPipeNode = (writable: StreamWritableNode) => void;
|
|
41
41
|
type StreamProviderNormalized = StreamReadableWeb | StreamReadableNode | StreamPipeWeb | StreamPipeNode;
|
|
42
|
-
type StreamProviderAny = StreamProviderNormalized |
|
|
42
|
+
type StreamProviderAny = StreamProviderNormalized | StreamFromReactStreamingPackagePublic | StreamPipeWebWrapped | StreamPipeNodeWrapped;
|
|
43
43
|
type StreamTypePatch = NodeJS.ReadableStream;
|
|
44
44
|
declare function isStreamReadableWeb(thing: unknown): thing is StreamReadableWeb;
|
|
45
45
|
declare function isStreamWritableWeb(thing: unknown): thing is StreamWritableWeb;
|
|
@@ -20,7 +20,7 @@ export { streamPipeNodeToString };
|
|
|
20
20
|
export { isStreamWritableWeb };
|
|
21
21
|
export { isStreamWritableNode };
|
|
22
22
|
import { assert, assertUsage, checkType, isObject, hasProp, objectAssign, capitalizeFirstLetter, assertWarning, isCallable, createDebugger, isBug } from '../utils.js';
|
|
23
|
-
import {
|
|
23
|
+
import { getStreamOfReactStreamingPackage, isStreamFromReactStreamingPackage, streamFromReactStreamingPackageToString } from './stream/react-streaming.js';
|
|
24
24
|
import { import_ } from '@brillout/import';
|
|
25
25
|
import pc from '@brillout/picocolors';
|
|
26
26
|
const debug = createDebugger('vike:stream');
|
|
@@ -358,9 +358,9 @@ async function processStream(streamOriginal, { injectStringAtBegin, injectString
|
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onFlush, onReadyToWrite }) {
|
|
361
|
-
if (
|
|
361
|
+
if (isStreamFromReactStreamingPackage(streamOriginal)) {
|
|
362
362
|
debug(`onRenderHtml() hook returned ${pc.cyan('react-streaming')} result`);
|
|
363
|
-
const stream =
|
|
363
|
+
const stream = getStreamOfReactStreamingPackage(streamOriginal);
|
|
364
364
|
streamOriginal = stream;
|
|
365
365
|
}
|
|
366
366
|
if (isStreamPipeNode(streamOriginal)) {
|
|
@@ -625,7 +625,7 @@ function isStream(something) {
|
|
|
625
625
|
isStreamReadableNode(something) ||
|
|
626
626
|
isStreamPipeNode(something) ||
|
|
627
627
|
isStreamPipeWeb(something) ||
|
|
628
|
-
|
|
628
|
+
isStreamFromReactStreamingPackage(something)) {
|
|
629
629
|
checkType(something);
|
|
630
630
|
return true;
|
|
631
631
|
}
|
|
@@ -730,8 +730,8 @@ async function streamToString(stream) {
|
|
|
730
730
|
if (isStreamPipeWeb(stream)) {
|
|
731
731
|
return await streamPipeWebToString(getStreamPipeWeb(stream));
|
|
732
732
|
}
|
|
733
|
-
if (
|
|
734
|
-
return await
|
|
733
|
+
if (isStreamFromReactStreamingPackage(stream)) {
|
|
734
|
+
return await streamFromReactStreamingPackageToString(stream);
|
|
735
735
|
}
|
|
736
736
|
assert(false);
|
|
737
737
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isVikeReactApp(): boolean;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { projectInfo };
|
|
2
2
|
export { PROJECT_VERSION };
|
|
3
|
-
declare const PROJECT_VERSION: "0.4.
|
|
3
|
+
declare const PROJECT_VERSION: "0.4.178";
|
|
4
4
|
declare const projectInfo: {
|
|
5
5
|
projectName: "Vike";
|
|
6
|
-
projectVersion: "0.4.
|
|
6
|
+
projectVersion: "0.4.178";
|
|
7
7
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vike",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.178",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "tsc --watch",
|
|
6
6
|
"build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",
|
|
@@ -138,7 +138,7 @@
|
|
|
138
138
|
}
|
|
139
139
|
},
|
|
140
140
|
"peerDependencies": {
|
|
141
|
-
"react-streaming": ">=0.3.
|
|
141
|
+
"react-streaming": ">=0.3.36",
|
|
142
142
|
"vite": ">=4.4.0"
|
|
143
143
|
},
|
|
144
144
|
"peerDependenciesMeta": {
|
|
@@ -209,7 +209,7 @@
|
|
|
209
209
|
"es-module-lexer": "^1.4.1",
|
|
210
210
|
"esbuild": "^0.19.10",
|
|
211
211
|
"fast-glob": "^3.3.2",
|
|
212
|
-
"react-streaming": "^0.3.
|
|
212
|
+
"react-streaming": "^0.3.36",
|
|
213
213
|
"rimraf": "^5.0.5",
|
|
214
214
|
"sirv": "^2.0.4",
|
|
215
215
|
"source-map-support": "^0.5.21",
|