Repository navigation
Expand file tree
/
Copy pathreact-router@8.4.0.patch
More file actions
154 lines (154 loc) · 5.05 KB
/
Copy pathreact-router@8.4.0.patch
File metadata and controls
154 lines (154 loc) · 5.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
diff --git a/dist/development/lib/rsc/html-stream/server.js b/dist/development/lib/rsc/html-stream/server.js
index 326e0ea1136babf7a9ed03bb59087140069758bf..ccfef142cb56f08bd58caf0eeb40790d61e1f7a6 100644
--- a/dist/development/lib/rsc/html-stream/server.js
+++ b/dist/development/lib/rsc/html-stream/server.js
@@ -21,11 +21,31 @@ function injectRSCPayload(rscStream, { nonce } = {}) {
let rscReader = null;
let buffered = [];
let timeout = null;
+ async function stop(reason) {
+ cancelled = true;
+ if (timeout) {
+ clearTimeout(timeout);
+ timeout = null;
+ }
+ buffered.length = 0;
+ resolveFlightDataPromise();
+ if (rscReader && rscStream.locked) await rscReader.cancel(reason).catch(() => {});
+ else await rscStream.cancel(reason).catch(() => {});
+ }
+ function tryEnqueue(controller, chunk) {
+ try {
+ controller.enqueue(chunk);
+ return true;
+ } catch (error) {
+ stop(error);
+ return false;
+ }
+ }
function flushBufferedChunks(controller) {
for (let chunk of buffered) {
let buf = decoder.decode(chunk, { stream: true });
if (buf.endsWith(trailer)) buf = buf.slice(0, -14);
- controller.enqueue(encoder.encode(buf));
+ if (!tryEnqueue(controller, encoder.encode(buf))) return;
}
buffered.length = 0;
timeout = null;
@@ -37,31 +57,28 @@ function injectRSCPayload(rscStream, { nonce } = {}) {
timeout = setTimeout(async () => {
if (cancelled) return;
flushBufferedChunks(controller);
+ if (cancelled) return;
if (!startedRSC) {
startedRSC = true;
rscReader = rscStream.getReader();
- writeRSCStream(rscReader, controller, () => cancelled, nonce).catch((err) => controller.error(err)).then(resolveFlightDataPromise);
+ writeRSCStream(rscReader, controller, () => cancelled, nonce).catch((err) => {
+ if (!cancelled) controller.error(err);
+ }).then(resolveFlightDataPromise);
}
}, 0);
},
async flush(controller) {
await flightDataPromise;
+ if (cancelled) return;
if (timeout) {
clearTimeout(timeout);
flushBufferedChunks(controller);
+ if (cancelled) return;
}
- controller.enqueue(encoder.encode("</body></html>"));
+ tryEnqueue(controller, encoder.encode("</body></html>"));
},
async cancel(reason) {
- cancelled = true;
- if (timeout) {
- clearTimeout(timeout);
- timeout = null;
- }
- buffered.length = 0;
- if (rscReader) await rscReader.cancel(reason).catch(() => {});
- else await rscStream.cancel(reason).catch(() => {});
- resolveFlightDataPromise();
+ await stop(reason);
}
});
}
diff --git a/dist/production/lib/rsc/html-stream/server.js b/dist/production/lib/rsc/html-stream/server.js
index 326e0ea1136babf7a9ed03bb59087140069758bf..ccfef142cb56f08bd58caf0eeb40790d61e1f7a6 100644
--- a/dist/production/lib/rsc/html-stream/server.js
+++ b/dist/production/lib/rsc/html-stream/server.js
@@ -21,11 +21,31 @@ function injectRSCPayload(rscStream, { nonce } = {}) {
let rscReader = null;
let buffered = [];
let timeout = null;
+ async function stop(reason) {
+ cancelled = true;
+ if (timeout) {
+ clearTimeout(timeout);
+ timeout = null;
+ }
+ buffered.length = 0;
+ resolveFlightDataPromise();
+ if (rscReader && rscStream.locked) await rscReader.cancel(reason).catch(() => {});
+ else await rscStream.cancel(reason).catch(() => {});
+ }
+ function tryEnqueue(controller, chunk) {
+ try {
+ controller.enqueue(chunk);
+ return true;
+ } catch (error) {
+ stop(error);
+ return false;
+ }
+ }
function flushBufferedChunks(controller) {
for (let chunk of buffered) {
let buf = decoder.decode(chunk, { stream: true });
if (buf.endsWith(trailer)) buf = buf.slice(0, -14);
- controller.enqueue(encoder.encode(buf));
+ if (!tryEnqueue(controller, encoder.encode(buf))) return;
}
buffered.length = 0;
timeout = null;
@@ -37,31 +57,28 @@ function injectRSCPayload(rscStream, { nonce } = {}) {
timeout = setTimeout(async () => {
if (cancelled) return;
flushBufferedChunks(controller);
+ if (cancelled) return;
if (!startedRSC) {
startedRSC = true;
rscReader = rscStream.getReader();
- writeRSCStream(rscReader, controller, () => cancelled, nonce).catch((err) => controller.error(err)).then(resolveFlightDataPromise);
+ writeRSCStream(rscReader, controller, () => cancelled, nonce).catch((err) => {
+ if (!cancelled) controller.error(err);
+ }).then(resolveFlightDataPromise);
}
}, 0);
},
async flush(controller) {
await flightDataPromise;
+ if (cancelled) return;
if (timeout) {
clearTimeout(timeout);
flushBufferedChunks(controller);
+ if (cancelled) return;
}
- controller.enqueue(encoder.encode("</body></html>"));
+ tryEnqueue(controller, encoder.encode("</body></html>"));
},
async cancel(reason) {
- cancelled = true;
- if (timeout) {
- clearTimeout(timeout);
- timeout = null;
- }
- buffered.length = 0;
- if (rscReader) await rscReader.cancel(reason).catch(() => {});
- else await rscStream.cancel(reason).catch(() => {});
- resolveFlightDataPromise();
+ await stop(reason);
}
});
}