Skip to content

Commit bcf4417

Browse files
Merge pull request #487 from preactjs/remove-spread
fix: remove spread to avoid stack limit error
2 parents 091e2eb + ccf67c4 commit bcf4417

File tree

3 files changed

+61
-43
lines changed

3 files changed

+61
-43
lines changed

src/adapter/debug.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,17 @@ export function fromSnapshot(events: string[]): number[] {
198198
}
199199
}
200200

201-
out.push(...flushTable(new Map(strings.map((x, i) => [x, i]))));
201+
const strs = flushTable(new Map(strings.map((x, i) => [x, i])));
202+
for (let i = 0; i < strs.length; i++) {
203+
out.push(strs[i]);
204+
}
202205
if (unmounts.length > 0) {
203206
out.push(MsgTypes.REMOVE_VNODE, unmounts.length, ...unmounts);
204207
}
205-
out.push(...operations);
208+
209+
for (let i = 0; i < operations.length; i++) {
210+
out.push(operations[i]);
211+
}
206212

207213
return out;
208214
}

src/adapter/protocol/events.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,12 @@ export function flush(commit: Commit) {
9393
if (unmountIds.length > 0) {
9494
msg.push(MsgTypes.REMOVE_VNODE, unmountIds.length, ...unmountIds);
9595
}
96-
msg.push(...operations);
96+
97+
for (let i = 0; i < operations.length; i++) {
98+
msg.push(operations[i]);
99+
}
97100
if (stats !== null) {
98-
msg.push(...stats2ops(stats));
101+
stats2ops(stats, msg);
99102
}
100103

101104
return { type: "operation_v2", data: msg };
@@ -201,7 +204,8 @@ export function applyEvent(store: Store, type: keyof DevtoolEvents, data: any) {
201204
store.profiler.isSupported.value = !!data.supportsProfiling;
202205
}
203206
if (!store.profiler.supportsRenderReasons.value) {
204-
store.profiler.supportsRenderReasons.value = !!data.supportsRenderReasons;
207+
store.profiler.supportsRenderReasons.value =
208+
!!data.supportsRenderReasons;
205209
}
206210

207211
if (!store.supports.hooks.value) {

src/adapter/shared/stats.ts

+46-38
Original file line numberDiff line numberDiff line change
@@ -113,44 +113,52 @@ export function createStats(): Stats {
113113
};
114114
}
115115

116-
export function stats2ops(stats: Stats): number[] {
117-
return [
118-
MsgTypes.COMMIT_STATS,
119-
...stats.roots,
120-
...stats.classComponents,
121-
...stats.functionComponents,
122-
...stats.fragments,
123-
...stats.forwardRef,
124-
...stats.memo,
125-
...stats.suspense,
126-
...stats.elements,
127-
stats.text,
128-
129-
...stats.keyed,
130-
...stats.unkeyed,
131-
...stats.mixed,
132-
133-
stats.mounts.components,
134-
stats.mounts.elements,
135-
stats.mounts.text,
136-
stats.updates.components,
137-
stats.updates.elements,
138-
stats.updates.text,
139-
stats.unmounts.components,
140-
stats.unmounts.elements,
141-
stats.unmounts.text,
142-
143-
// Single child types
144-
stats.singleChildType.roots,
145-
stats.singleChildType.classComponents,
146-
stats.singleChildType.functionComponents,
147-
stats.singleChildType.fragments,
148-
stats.singleChildType.forwardRef,
149-
stats.singleChildType.memo,
150-
stats.singleChildType.suspense,
151-
stats.singleChildType.elements,
152-
stats.singleChildType.text,
153-
];
116+
export function stats2ops(stats: Stats, out: number[]): void {
117+
out.push(MsgTypes.COMMIT_STATS);
118+
119+
pushStatsChildren(out, stats.roots);
120+
pushStatsChildren(out, stats.classComponents);
121+
pushStatsChildren(out, stats.functionComponents);
122+
pushStatsChildren(out, stats.fragments);
123+
pushStatsChildren(out, stats.forwardRef);
124+
pushStatsChildren(out, stats.memo);
125+
pushStatsChildren(out, stats.suspense);
126+
pushStatsChildren(out, stats.elements);
127+
128+
out.push(stats.text);
129+
130+
pushStatsChildren(out, stats.keyed);
131+
pushStatsChildren(out, stats.unkeyed);
132+
pushStatsChildren(out, stats.mixed);
133+
134+
out.push(stats.mounts.components);
135+
out.push(stats.mounts.elements);
136+
out.push(stats.mounts.text);
137+
out.push(stats.updates.components);
138+
out.push(stats.updates.elements);
139+
out.push(stats.updates.text);
140+
out.push(stats.unmounts.components);
141+
out.push(stats.unmounts.elements);
142+
out.push(stats.unmounts.text);
143+
144+
// Single child types
145+
out.push(stats.singleChildType.roots);
146+
out.push(stats.singleChildType.classComponents);
147+
out.push(stats.singleChildType.functionComponents);
148+
out.push(stats.singleChildType.fragments);
149+
out.push(stats.singleChildType.forwardRef);
150+
out.push(stats.singleChildType.memo);
151+
out.push(stats.singleChildType.suspense);
152+
out.push(stats.singleChildType.elements);
153+
out.push(stats.singleChildType.text);
154+
}
155+
156+
function pushStatsChildren(out: number[], stats: StatsChildren): void {
157+
out.push(stats[0]);
158+
out.push(stats[1]);
159+
out.push(stats[2]);
160+
out.push(stats[3]);
161+
out.push(stats[4]);
154162
}
155163

156164
export interface ParsedStats {

0 commit comments

Comments
 (0)