@modern-js/render 2.70.3 → 2.70.5
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.
|
@@ -21,6 +21,9 @@ __export(processRSCStream_exports, {
|
|
|
21
21
|
processRSCStream: () => processRSCStream
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(processRSCStream_exports);
|
|
24
|
+
function escapeScript(script) {
|
|
25
|
+
return script.replace(/<!--/g, "<\\!--").replace(/<\/(script)/gi, "</\\$1");
|
|
26
|
+
}
|
|
24
27
|
async function processRSCStream(rscStream, controller, encoder) {
|
|
25
28
|
try {
|
|
26
29
|
const reader = rscStream.getReader();
|
|
@@ -35,17 +38,20 @@ async function processRSCStream(rscStream, controller, encoder) {
|
|
|
35
38
|
const chunk = JSON.stringify(decoder.decode(value, {
|
|
36
39
|
stream: true
|
|
37
40
|
}));
|
|
38
|
-
const
|
|
41
|
+
const scriptContent = `(self.__FLIGHT_DATA||=[]).push(${chunk})`;
|
|
42
|
+
const scriptTag = `<script>${escapeScript(scriptContent)}</script>`;
|
|
39
43
|
controller.enqueue(encoder.encode(scriptTag));
|
|
40
44
|
} catch (err) {
|
|
41
45
|
const base64 = JSON.stringify(btoa(String.fromCodePoint(...value)));
|
|
42
|
-
const
|
|
46
|
+
const scriptContent = `(self.__FLIGHT_DATA||=[]).push(Uint8Array.from(atob(${base64}), m => m.codePointAt(0)))`;
|
|
47
|
+
const scriptTag = `<script>${escapeScript(scriptContent)}</script>`;
|
|
43
48
|
controller.enqueue(encoder.encode(scriptTag));
|
|
44
49
|
}
|
|
45
50
|
}
|
|
46
51
|
const remaining = decoder.decode();
|
|
47
52
|
if (remaining.length) {
|
|
48
|
-
const
|
|
53
|
+
const scriptContent = `(self.__FLIGHT_DATA||=[]).push(${JSON.stringify(remaining)})`;
|
|
54
|
+
const scriptTag = `<script>${escapeScript(scriptContent)}</script>`;
|
|
49
55
|
controller.enqueue(encoder.encode(scriptTag));
|
|
50
56
|
}
|
|
51
57
|
controller.close();
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
3
3
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
|
+
function escapeScript(script) {
|
|
5
|
+
return script.replace(/<!--/g, "<\\!--").replace(/<\/(script)/gi, "</\\$1");
|
|
6
|
+
}
|
|
4
7
|
function processRSCStream(rscStream, controller, encoder) {
|
|
5
8
|
return _processRSCStream.apply(this, arguments);
|
|
6
9
|
}
|
|
7
10
|
function _processRSCStream() {
|
|
8
11
|
_processRSCStream = _async_to_generator(function(rscStream, controller, encoder) {
|
|
9
|
-
var reader, decoder, _ref, done, value, chunk, scriptTag, _String, base64, scriptTag1, remaining, scriptTag2, error;
|
|
12
|
+
var reader, decoder, _ref, done, value, chunk, scriptContent, scriptTag, _String, base64, scriptContent1, scriptTag1, remaining, scriptContent2, scriptTag2, error;
|
|
10
13
|
return _ts_generator(this, function(_state) {
|
|
11
14
|
switch (_state.label) {
|
|
12
15
|
case 0:
|
|
@@ -42,12 +45,14 @@ function _processRSCStream() {
|
|
|
42
45
|
chunk = JSON.stringify(decoder.decode(value, {
|
|
43
46
|
stream: true
|
|
44
47
|
}));
|
|
45
|
-
|
|
48
|
+
scriptContent = "(self.__FLIGHT_DATA||=[]).push(".concat(chunk, ")");
|
|
49
|
+
scriptTag = "<script>".concat(escapeScript(scriptContent), "</script>");
|
|
46
50
|
controller.enqueue(encoder.encode(scriptTag));
|
|
47
51
|
} catch (err) {
|
|
48
52
|
;
|
|
49
53
|
base64 = JSON.stringify(btoa((_String = String).fromCodePoint.apply(_String, _to_consumable_array(value))));
|
|
50
|
-
|
|
54
|
+
scriptContent1 = "(self.__FLIGHT_DATA||=[]).push(Uint8Array.from(atob(".concat(base64, "), m => m.codePointAt(0)))");
|
|
55
|
+
scriptTag1 = "<script>".concat(escapeScript(scriptContent1), "</script>");
|
|
51
56
|
controller.enqueue(encoder.encode(scriptTag1));
|
|
52
57
|
}
|
|
53
58
|
return [
|
|
@@ -57,7 +62,8 @@ function _processRSCStream() {
|
|
|
57
62
|
case 3:
|
|
58
63
|
remaining = decoder.decode();
|
|
59
64
|
if (remaining.length) {
|
|
60
|
-
|
|
65
|
+
scriptContent2 = "(self.__FLIGHT_DATA||=[]).push(".concat(JSON.stringify(remaining), ")");
|
|
66
|
+
scriptTag2 = "<script>".concat(escapeScript(scriptContent2), "</script>");
|
|
61
67
|
controller.enqueue(encoder.encode(scriptTag2));
|
|
62
68
|
}
|
|
63
69
|
controller.close();
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
function escapeScript(script) {
|
|
2
|
+
return script.replace(/<!--/g, "<\\!--").replace(/<\/(script)/gi, "</\\$1");
|
|
3
|
+
}
|
|
1
4
|
async function processRSCStream(rscStream, controller, encoder) {
|
|
2
5
|
try {
|
|
3
6
|
const reader = rscStream.getReader();
|
|
@@ -12,17 +15,20 @@ async function processRSCStream(rscStream, controller, encoder) {
|
|
|
12
15
|
const chunk = JSON.stringify(decoder.decode(value, {
|
|
13
16
|
stream: true
|
|
14
17
|
}));
|
|
15
|
-
const
|
|
18
|
+
const scriptContent = `(self.__FLIGHT_DATA||=[]).push(${chunk})`;
|
|
19
|
+
const scriptTag = `<script>${escapeScript(scriptContent)}</script>`;
|
|
16
20
|
controller.enqueue(encoder.encode(scriptTag));
|
|
17
21
|
} catch (err) {
|
|
18
22
|
const base64 = JSON.stringify(btoa(String.fromCodePoint(...value)));
|
|
19
|
-
const
|
|
23
|
+
const scriptContent = `(self.__FLIGHT_DATA||=[]).push(Uint8Array.from(atob(${base64}), m => m.codePointAt(0)))`;
|
|
24
|
+
const scriptTag = `<script>${escapeScript(scriptContent)}</script>`;
|
|
20
25
|
controller.enqueue(encoder.encode(scriptTag));
|
|
21
26
|
}
|
|
22
27
|
}
|
|
23
28
|
const remaining = decoder.decode();
|
|
24
29
|
if (remaining.length) {
|
|
25
|
-
const
|
|
30
|
+
const scriptContent = `(self.__FLIGHT_DATA||=[]).push(${JSON.stringify(remaining)})`;
|
|
31
|
+
const scriptTag = `<script>${escapeScript(scriptContent)}</script>`;
|
|
26
32
|
controller.enqueue(encoder.encode(scriptTag));
|
|
27
33
|
}
|
|
28
34
|
controller.close();
|
package/package.json
CHANGED
|
@@ -15,15 +15,15 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.70.
|
|
18
|
+
"version": "2.70.5",
|
|
19
19
|
"files": [
|
|
20
20
|
"dist",
|
|
21
21
|
"hook.d.ts"
|
|
22
22
|
],
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@swc/helpers": "^0.5.17",
|
|
25
|
-
"@modern-js/types": "2.70.
|
|
26
|
-
"@modern-js/utils": "2.70.
|
|
25
|
+
"@modern-js/types": "2.70.5",
|
|
26
|
+
"@modern-js/utils": "2.70.5"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/jest": "^29",
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
"react": "^18.3.1",
|
|
34
34
|
"react-dom": "^18.3.1",
|
|
35
35
|
"typescript": "^5",
|
|
36
|
-
"@modern-js/server-core": "2.70.
|
|
36
|
+
"@modern-js/server-core": "2.70.5"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"react": ">=17.0.0",
|
|
40
40
|
"react-dom": ">=17.0.0",
|
|
41
|
-
"react-server-dom-webpack": "^19.
|
|
41
|
+
"react-server-dom-webpack": "^19.2.4"
|
|
42
42
|
},
|
|
43
43
|
"exports": {
|
|
44
44
|
"./ssr": {
|