@modern-js/runtime 2.68.20 → 2.69.1

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.
@@ -78,9 +78,34 @@ const createReadableStreamFromElement = async (request, rootElement, options) =>
78
78
  start(controller) {
79
79
  var _storage_useContext, _options_runtimeContext, _storageContext_activeDeferreds;
80
80
  const pendingScripts = [];
81
+ let isClosed = false;
82
+ const safeEnqueue = (chunk) => {
83
+ if (isClosed)
84
+ return;
85
+ try {
86
+ controller.enqueue(chunk);
87
+ } catch {
88
+ isClosed = true;
89
+ }
90
+ };
91
+ const closeController = () => {
92
+ if (!isClosed) {
93
+ isClosed = true;
94
+ try {
95
+ controller.close();
96
+ } catch {
97
+ }
98
+ }
99
+ };
100
+ const flushPendingScripts = () => {
101
+ for (const s of pendingScripts) {
102
+ safeEnqueue((0, import_shared.encodeForWebStream)(s));
103
+ }
104
+ pendingScripts.length = 0;
105
+ };
81
106
  const enqueueScript = (script) => {
82
107
  if (shellChunkStatus === import_shared.ShellChunkStatus.FINISH) {
83
- controller.enqueue((0, import_shared.encodeForWebStream)(script));
108
+ safeEnqueue((0, import_shared.encodeForWebStream)(script));
84
109
  } else {
85
110
  pendingScripts.push(script);
86
111
  }
@@ -89,35 +114,45 @@ const createReadableStreamFromElement = async (request, rootElement, options) =>
89
114
  const routerContext = (_options_runtimeContext = options.runtimeContext) === null || _options_runtimeContext === void 0 ? void 0 : _options_runtimeContext.routerContext;
90
115
  const entries = (storageContext === null || storageContext === void 0 ? void 0 : storageContext.activeDeferreds) instanceof Map && ((_storageContext_activeDeferreds = storageContext.activeDeferreds) === null || _storageContext_activeDeferreds === void 0 ? void 0 : _storageContext_activeDeferreds.size) > 0 ? Array.from(storageContext.activeDeferreds.entries()) : (routerContext === null || routerContext === void 0 ? void 0 : routerContext.activeDeferreds) ? Object.entries(routerContext.activeDeferreds) : [];
91
116
  if (entries.length > 0) {
92
- (0, import_deferredScript.enqueueFromEntries)(entries, config.nonce, (s) => enqueueScript(s));
117
+ (0, import_deferredScript.enqueueFromEntries)(entries, config.nonce, enqueueScript);
93
118
  }
94
119
  async function push() {
95
- const { done, value } = await reader.read();
96
- if (done) {
97
- controller.close();
98
- return;
99
- }
100
- if (shellChunkStatus !== import_shared.ShellChunkStatus.FINISH) {
101
- const chunk = new TextDecoder().decode(value);
102
- chunkVec.push(chunk);
103
- let concatedChunk = chunkVec.join("");
104
- if (concatedChunk.includes(import_common.ESCAPED_SHELL_STREAM_END_MARK)) {
105
- concatedChunk = concatedChunk.replace(import_common.ESCAPED_SHELL_STREAM_END_MARK, "");
106
- shellChunkStatus = import_shared.ShellChunkStatus.FINISH;
107
- controller.enqueue((0, import_shared.encodeForWebStream)(`${shellBefore}${concatedChunk}${shellAfter}`));
108
- if (pendingScripts.length > 0) {
109
- for (const s of pendingScripts) {
110
- controller.enqueue((0, import_shared.encodeForWebStream)(s));
111
- }
112
- pendingScripts.length = 0;
120
+ try {
121
+ const { done, value } = await reader.read();
122
+ if (done) {
123
+ closeController();
124
+ return;
125
+ }
126
+ if (isClosed)
127
+ return;
128
+ if (shellChunkStatus !== import_shared.ShellChunkStatus.FINISH) {
129
+ chunkVec.push(new TextDecoder().decode(value));
130
+ const concatedChunk = chunkVec.join("");
131
+ if (concatedChunk.includes(import_common.ESCAPED_SHELL_STREAM_END_MARK)) {
132
+ shellChunkStatus = import_shared.ShellChunkStatus.FINISH;
133
+ safeEnqueue((0, import_shared.encodeForWebStream)(`${shellBefore}${concatedChunk.replace(import_common.ESCAPED_SHELL_STREAM_END_MARK, "")}${shellAfter}`));
134
+ flushPendingScripts();
135
+ }
136
+ } else {
137
+ safeEnqueue(value);
138
+ }
139
+ if (!isClosed)
140
+ push();
141
+ } catch (error) {
142
+ if (!isClosed) {
143
+ isClosed = true;
144
+ try {
145
+ controller.error(error);
146
+ } catch {
113
147
  }
114
148
  }
115
- } else {
116
- controller.enqueue(value);
117
149
  }
118
- push();
119
150
  }
120
151
  push();
152
+ },
153
+ cancel(reason) {
154
+ reader.cancel(reason).catch(() => {
155
+ });
121
156
  }
122
157
  });
123
158
  return stream;
@@ -171,7 +171,7 @@ const documentPlugin = () => ({
171
171
  if (html.includes(import_constants.DOCUMENT_SCRIPT_PLACEHOLDER_START) && html.includes(import_constants.DOCUMENT_SCRIPT_PLACEHOLDER_END)) {
172
172
  const { nonce } = config.security || {};
173
173
  const nonceAttr = nonce ? `nonce=${nonce}` : "";
174
- html = html.replace(new RegExp(`${import_constants.DOCUMENT_SCRIPT_PLACEHOLDER_START}${import_constants.DOCUMENT_SCRIPT_ATTRIBUTES_START}(.*)${import_constants.DOCUMENT_SCRIPT_ATTRIBUTES_END}(.*?)${import_constants.DOCUMENT_SCRIPT_PLACEHOLDER_END}`, "g"), (_scriptStr, $1, $2) => `<script ${decodeURIComponent($1)} ${nonceAttr}>${decodeURIComponent($2)}</script>`);
174
+ html = html.replace(new RegExp(`${import_constants.DOCUMENT_SCRIPT_PLACEHOLDER_START}${import_constants.DOCUMENT_SCRIPT_ATTRIBUTES_START}(.*?)${import_constants.DOCUMENT_SCRIPT_ATTRIBUTES_END}(.*?)${import_constants.DOCUMENT_SCRIPT_PLACEHOLDER_END}`, "g"), (_scriptStr, $1, $2) => `<script ${decodeURIComponent($1)} ${nonceAttr}>${decodeURIComponent($2)}</script>`);
175
175
  }
176
176
  if (html.includes(import_constants.DOCUMENT_STYLE_PLACEHOLDER_START) && html.includes(import_constants.DOCUMENT_STYLE_PLACEHOLDER_END)) {
177
177
  html = html.replace(new RegExp(`${import_constants.DOCUMENT_STYLE_PLACEHOLDER_START}(.*?)${import_constants.DOCUMENT_STYLE_PLACEHOLDER_END}`, "g"), (_styleStr, $1) => `<style>${decodeURIComponent($1)}</style>`);
@@ -79,9 +79,51 @@ var createReadableStreamFromElement = function() {
79
79
  start: function start(controller) {
80
80
  var _storage_useContext, _options_runtimeContext, _storageContext_activeDeferreds;
81
81
  var pendingScripts = [];
82
+ var isClosed = false;
83
+ var safeEnqueue = function(chunk) {
84
+ if (isClosed)
85
+ return;
86
+ try {
87
+ controller.enqueue(chunk);
88
+ } catch (e2) {
89
+ isClosed = true;
90
+ }
91
+ };
92
+ var closeController = function() {
93
+ if (!isClosed) {
94
+ isClosed = true;
95
+ try {
96
+ controller.close();
97
+ } catch (e2) {
98
+ }
99
+ }
100
+ };
101
+ var flushPendingScripts = function() {
102
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
103
+ try {
104
+ for (var _iterator = pendingScripts[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
105
+ var s = _step.value;
106
+ safeEnqueue(encodeForWebStream(s));
107
+ }
108
+ } catch (err) {
109
+ _didIteratorError = true;
110
+ _iteratorError = err;
111
+ } finally {
112
+ try {
113
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
114
+ _iterator.return();
115
+ }
116
+ } finally {
117
+ if (_didIteratorError) {
118
+ throw _iteratorError;
119
+ }
120
+ }
121
+ }
122
+ pendingScripts.length = 0;
123
+ };
82
124
  var enqueueScript = function(script) {
83
125
  if (shellChunkStatus === ShellChunkStatus.FINISH) {
84
- controller.enqueue(encodeForWebStream(script));
126
+ safeEnqueue(encodeForWebStream(script));
85
127
  } else {
86
128
  pendingScripts.push(script);
87
129
  }
@@ -90,19 +132,23 @@ var createReadableStreamFromElement = function() {
90
132
  var routerContext = (_options_runtimeContext = options.runtimeContext) === null || _options_runtimeContext === void 0 ? void 0 : _options_runtimeContext.routerContext;
91
133
  var entries = _instanceof(storageContext === null || storageContext === void 0 ? void 0 : storageContext.activeDeferreds, Map) && ((_storageContext_activeDeferreds = storageContext.activeDeferreds) === null || _storageContext_activeDeferreds === void 0 ? void 0 : _storageContext_activeDeferreds.size) > 0 ? Array.from(storageContext.activeDeferreds.entries()) : (routerContext === null || routerContext === void 0 ? void 0 : routerContext.activeDeferreds) ? Object.entries(routerContext.activeDeferreds) : [];
92
134
  if (entries.length > 0) {
93
- enqueueFromEntries(entries, config.nonce, function(s) {
94
- return enqueueScript(s);
95
- });
135
+ enqueueFromEntries(entries, config.nonce, enqueueScript);
96
136
  }
97
137
  function push() {
98
138
  return _push.apply(this, arguments);
99
139
  }
100
140
  function _push() {
101
141
  _push = _async_to_generator(function() {
102
- var _ref3, done, value, chunk, concatedChunk, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, s;
142
+ var _ref3, done, value, concatedChunk, error;
103
143
  return _ts_generator(this, function(_state2) {
104
144
  switch (_state2.label) {
105
145
  case 0:
146
+ _state2.trys.push([
147
+ 0,
148
+ 2,
149
+ ,
150
+ 3
151
+ ]);
106
152
  return [
107
153
  4,
108
154
  reader.read()
@@ -110,47 +156,46 @@ var createReadableStreamFromElement = function() {
110
156
  case 1:
111
157
  _ref3 = _state2.sent(), done = _ref3.done, value = _ref3.value;
112
158
  if (done) {
113
- controller.close();
159
+ closeController();
114
160
  return [
115
161
  2
116
162
  ];
117
163
  }
164
+ if (isClosed)
165
+ return [
166
+ 2
167
+ ];
118
168
  if (shellChunkStatus !== ShellChunkStatus.FINISH) {
119
- chunk = new TextDecoder().decode(value);
120
- chunkVec.push(chunk);
169
+ chunkVec.push(new TextDecoder().decode(value));
121
170
  concatedChunk = chunkVec.join("");
122
171
  if (concatedChunk.includes(ESCAPED_SHELL_STREAM_END_MARK)) {
123
- concatedChunk = concatedChunk.replace(ESCAPED_SHELL_STREAM_END_MARK, "");
124
172
  shellChunkStatus = ShellChunkStatus.FINISH;
125
- controller.enqueue(encodeForWebStream("".concat(shellBefore).concat(concatedChunk).concat(shellAfter)));
126
- if (pendingScripts.length > 0) {
127
- _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
128
- try {
129
- for (_iterator = pendingScripts[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
130
- s = _step.value;
131
- controller.enqueue(encodeForWebStream(s));
132
- }
133
- } catch (err) {
134
- _didIteratorError = true;
135
- _iteratorError = err;
136
- } finally {
137
- try {
138
- if (!_iteratorNormalCompletion && _iterator.return != null) {
139
- _iterator.return();
140
- }
141
- } finally {
142
- if (_didIteratorError) {
143
- throw _iteratorError;
144
- }
145
- }
146
- }
147
- pendingScripts.length = 0;
148
- }
173
+ safeEnqueue(encodeForWebStream("".concat(shellBefore).concat(concatedChunk.replace(ESCAPED_SHELL_STREAM_END_MARK, "")).concat(shellAfter)));
174
+ flushPendingScripts();
149
175
  }
150
176
  } else {
151
- controller.enqueue(value);
177
+ safeEnqueue(value);
152
178
  }
153
- push();
179
+ if (!isClosed)
180
+ push();
181
+ return [
182
+ 3,
183
+ 3
184
+ ];
185
+ case 2:
186
+ error = _state2.sent();
187
+ if (!isClosed) {
188
+ isClosed = true;
189
+ try {
190
+ controller.error(error);
191
+ } catch (e2) {
192
+ }
193
+ }
194
+ return [
195
+ 3,
196
+ 3
197
+ ];
198
+ case 3:
154
199
  return [
155
200
  2
156
201
  ];
@@ -160,6 +205,10 @@ var createReadableStreamFromElement = function() {
160
205
  return _push.apply(this, arguments);
161
206
  }
162
207
  push();
208
+ },
209
+ cancel: function cancel(reason) {
210
+ reader.cancel(reason).catch(function() {
211
+ });
163
212
  }
164
213
  });
165
214
  return [
@@ -197,7 +197,7 @@ var documentPlugin = function() {
197
197
  if (html.includes(DOCUMENT_SCRIPT_PLACEHOLDER_START) && html.includes(DOCUMENT_SCRIPT_PLACEHOLDER_END)) {
198
198
  nonce = (config.security || {}).nonce;
199
199
  nonceAttr = nonce ? "nonce=".concat(nonce) : "";
200
- html = html.replace(new RegExp("".concat(DOCUMENT_SCRIPT_PLACEHOLDER_START).concat(DOCUMENT_SCRIPT_ATTRIBUTES_START, "(.*)").concat(DOCUMENT_SCRIPT_ATTRIBUTES_END, "(.*?)").concat(DOCUMENT_SCRIPT_PLACEHOLDER_END), "g"), function(_scriptStr, $1, $2) {
200
+ html = html.replace(new RegExp("".concat(DOCUMENT_SCRIPT_PLACEHOLDER_START).concat(DOCUMENT_SCRIPT_ATTRIBUTES_START, "(.*?)").concat(DOCUMENT_SCRIPT_ATTRIBUTES_END, "(.*?)").concat(DOCUMENT_SCRIPT_PLACEHOLDER_END), "g"), function(_scriptStr, $1, $2) {
201
201
  return "<script ".concat(decodeURIComponent($1), " ").concat(nonceAttr, ">").concat(decodeURIComponent($2), "</script>");
202
202
  });
203
203
  }
@@ -45,9 +45,34 @@ const createReadableStreamFromElement = async (request, rootElement, options) =>
45
45
  start(controller) {
46
46
  var _storage_useContext, _options_runtimeContext, _storageContext_activeDeferreds;
47
47
  const pendingScripts = [];
48
+ let isClosed = false;
49
+ const safeEnqueue = (chunk) => {
50
+ if (isClosed)
51
+ return;
52
+ try {
53
+ controller.enqueue(chunk);
54
+ } catch {
55
+ isClosed = true;
56
+ }
57
+ };
58
+ const closeController = () => {
59
+ if (!isClosed) {
60
+ isClosed = true;
61
+ try {
62
+ controller.close();
63
+ } catch {
64
+ }
65
+ }
66
+ };
67
+ const flushPendingScripts = () => {
68
+ for (const s of pendingScripts) {
69
+ safeEnqueue(encodeForWebStream(s));
70
+ }
71
+ pendingScripts.length = 0;
72
+ };
48
73
  const enqueueScript = (script) => {
49
74
  if (shellChunkStatus === ShellChunkStatus.FINISH) {
50
- controller.enqueue(encodeForWebStream(script));
75
+ safeEnqueue(encodeForWebStream(script));
51
76
  } else {
52
77
  pendingScripts.push(script);
53
78
  }
@@ -56,35 +81,45 @@ const createReadableStreamFromElement = async (request, rootElement, options) =>
56
81
  const routerContext = (_options_runtimeContext = options.runtimeContext) === null || _options_runtimeContext === void 0 ? void 0 : _options_runtimeContext.routerContext;
57
82
  const entries = (storageContext === null || storageContext === void 0 ? void 0 : storageContext.activeDeferreds) instanceof Map && ((_storageContext_activeDeferreds = storageContext.activeDeferreds) === null || _storageContext_activeDeferreds === void 0 ? void 0 : _storageContext_activeDeferreds.size) > 0 ? Array.from(storageContext.activeDeferreds.entries()) : (routerContext === null || routerContext === void 0 ? void 0 : routerContext.activeDeferreds) ? Object.entries(routerContext.activeDeferreds) : [];
58
83
  if (entries.length > 0) {
59
- enqueueFromEntries(entries, config.nonce, (s) => enqueueScript(s));
84
+ enqueueFromEntries(entries, config.nonce, enqueueScript);
60
85
  }
61
86
  async function push() {
62
- const { done, value } = await reader.read();
63
- if (done) {
64
- controller.close();
65
- return;
66
- }
67
- if (shellChunkStatus !== ShellChunkStatus.FINISH) {
68
- const chunk = new TextDecoder().decode(value);
69
- chunkVec.push(chunk);
70
- let concatedChunk = chunkVec.join("");
71
- if (concatedChunk.includes(ESCAPED_SHELL_STREAM_END_MARK)) {
72
- concatedChunk = concatedChunk.replace(ESCAPED_SHELL_STREAM_END_MARK, "");
73
- shellChunkStatus = ShellChunkStatus.FINISH;
74
- controller.enqueue(encodeForWebStream(`${shellBefore}${concatedChunk}${shellAfter}`));
75
- if (pendingScripts.length > 0) {
76
- for (const s of pendingScripts) {
77
- controller.enqueue(encodeForWebStream(s));
78
- }
79
- pendingScripts.length = 0;
87
+ try {
88
+ const { done, value } = await reader.read();
89
+ if (done) {
90
+ closeController();
91
+ return;
92
+ }
93
+ if (isClosed)
94
+ return;
95
+ if (shellChunkStatus !== ShellChunkStatus.FINISH) {
96
+ chunkVec.push(new TextDecoder().decode(value));
97
+ const concatedChunk = chunkVec.join("");
98
+ if (concatedChunk.includes(ESCAPED_SHELL_STREAM_END_MARK)) {
99
+ shellChunkStatus = ShellChunkStatus.FINISH;
100
+ safeEnqueue(encodeForWebStream(`${shellBefore}${concatedChunk.replace(ESCAPED_SHELL_STREAM_END_MARK, "")}${shellAfter}`));
101
+ flushPendingScripts();
102
+ }
103
+ } else {
104
+ safeEnqueue(value);
105
+ }
106
+ if (!isClosed)
107
+ push();
108
+ } catch (error) {
109
+ if (!isClosed) {
110
+ isClosed = true;
111
+ try {
112
+ controller.error(error);
113
+ } catch {
80
114
  }
81
115
  }
82
- } else {
83
- controller.enqueue(value);
84
116
  }
85
- push();
86
117
  }
87
118
  push();
119
+ },
120
+ cancel(reason) {
121
+ reader.cancel(reason).catch(() => {
122
+ });
88
123
  }
89
124
  });
90
125
  return stream;
@@ -136,7 +136,7 @@ const documentPlugin = () => ({
136
136
  if (html.includes(DOCUMENT_SCRIPT_PLACEHOLDER_START) && html.includes(DOCUMENT_SCRIPT_PLACEHOLDER_END)) {
137
137
  const { nonce } = config.security || {};
138
138
  const nonceAttr = nonce ? `nonce=${nonce}` : "";
139
- html = html.replace(new RegExp(`${DOCUMENT_SCRIPT_PLACEHOLDER_START}${DOCUMENT_SCRIPT_ATTRIBUTES_START}(.*)${DOCUMENT_SCRIPT_ATTRIBUTES_END}(.*?)${DOCUMENT_SCRIPT_PLACEHOLDER_END}`, "g"), (_scriptStr, $1, $2) => `<script ${decodeURIComponent($1)} ${nonceAttr}>${decodeURIComponent($2)}</script>`);
139
+ html = html.replace(new RegExp(`${DOCUMENT_SCRIPT_PLACEHOLDER_START}${DOCUMENT_SCRIPT_ATTRIBUTES_START}(.*?)${DOCUMENT_SCRIPT_ATTRIBUTES_END}(.*?)${DOCUMENT_SCRIPT_PLACEHOLDER_END}`, "g"), (_scriptStr, $1, $2) => `<script ${decodeURIComponent($1)} ${nonceAttr}>${decodeURIComponent($2)}</script>`);
140
140
  }
141
141
  if (html.includes(DOCUMENT_STYLE_PLACEHOLDER_START) && html.includes(DOCUMENT_STYLE_PLACEHOLDER_END)) {
142
142
  html = html.replace(new RegExp(`${DOCUMENT_STYLE_PLACEHOLDER_START}(.*?)${DOCUMENT_STYLE_PLACEHOLDER_END}`, "g"), (_styleStr, $1) => `<style>${decodeURIComponent($1)}</style>`);
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.68.20",
18
+ "version": "2.69.1",
19
19
  "engines": {
20
20
  "node": ">=14.17.6"
21
21
  },
@@ -219,13 +219,13 @@
219
219
  "react-is": "^18",
220
220
  "react-side-effect": "^2.1.2",
221
221
  "styled-components": "^5.3.1",
222
- "@modern-js/plugin": "2.68.20",
223
- "@modern-js/plugin-data-loader": "2.68.20",
224
- "@modern-js/render": "2.68.20",
225
- "@modern-js/plugin-v2": "2.68.20",
226
- "@modern-js/runtime-utils": "2.68.20",
227
- "@modern-js/types": "2.68.20",
228
- "@modern-js/utils": "2.68.20"
222
+ "@modern-js/plugin": "2.69.1",
223
+ "@modern-js/plugin-data-loader": "2.69.1",
224
+ "@modern-js/plugin-v2": "2.69.1",
225
+ "@modern-js/render": "2.69.1",
226
+ "@modern-js/runtime-utils": "2.69.1",
227
+ "@modern-js/types": "2.69.1",
228
+ "@modern-js/utils": "2.69.1"
229
229
  },
230
230
  "peerDependencies": {
231
231
  "react": ">=17",
@@ -233,7 +233,7 @@
233
233
  },
234
234
  "devDependencies": {
235
235
  "@remix-run/web-fetch": "^4.1.3",
236
- "@rsbuild/core": "1.6.3",
236
+ "@rsbuild/core": "1.6.7",
237
237
  "@testing-library/react": "^13.4.0",
238
238
  "@types/cookie": "0.6.0",
239
239
  "@types/invariant": "^2.2.30",
@@ -249,10 +249,10 @@
249
249
  "ts-node": "^10.9.1",
250
250
  "typescript": "^5",
251
251
  "webpack": "^5.102.1",
252
- "@modern-js/app-tools": "2.68.20",
252
+ "@modern-js/app-tools": "2.69.1",
253
253
  "@scripts/build": "2.66.0",
254
254
  "@scripts/jest-config": "2.66.0",
255
- "@modern-js/core": "2.68.20"
255
+ "@modern-js/core": "2.69.1"
256
256
  },
257
257
  "sideEffects": false,
258
258
  "publishConfig": {