Skip to content

Commit

Permalink
Merge pull request #487 from preactjs/remove-spread
Browse files Browse the repository at this point in the history
fix: remove spread to avoid stack limit error
  • Loading branch information
marvinhagemeister committed Apr 25, 2024
2 parents 091e2eb + ccf67c4 commit bcf4417
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 43 deletions.
10 changes: 8 additions & 2 deletions src/adapter/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,17 @@ export function fromSnapshot(events: string[]): number[] {
}
}

out.push(...flushTable(new Map(strings.map((x, i) => [x, i]))));
const strs = flushTable(new Map(strings.map((x, i) => [x, i])));
for (let i = 0; i < strs.length; i++) {
out.push(strs[i]);
}
if (unmounts.length > 0) {
out.push(MsgTypes.REMOVE_VNODE, unmounts.length, ...unmounts);
}
out.push(...operations);

for (let i = 0; i < operations.length; i++) {
out.push(operations[i]);
}

return out;
}
Expand Down
10 changes: 7 additions & 3 deletions src/adapter/protocol/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,12 @@ export function flush(commit: Commit) {
if (unmountIds.length > 0) {
msg.push(MsgTypes.REMOVE_VNODE, unmountIds.length, ...unmountIds);
}
msg.push(...operations);

for (let i = 0; i < operations.length; i++) {
msg.push(operations[i]);
}
if (stats !== null) {
msg.push(...stats2ops(stats));
stats2ops(stats, msg);
}

return { type: "operation_v2", data: msg };
Expand Down Expand Up @@ -201,7 +204,8 @@ export function applyEvent(store: Store, type: keyof DevtoolEvents, data: any) {
store.profiler.isSupported.value = !!data.supportsProfiling;
}
if (!store.profiler.supportsRenderReasons.value) {
store.profiler.supportsRenderReasons.value = !!data.supportsRenderReasons;
store.profiler.supportsRenderReasons.value =
!!data.supportsRenderReasons;
}

if (!store.supports.hooks.value) {
Expand Down
84 changes: 46 additions & 38 deletions src/adapter/shared/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,44 +113,52 @@ export function createStats(): Stats {
};
}

export function stats2ops(stats: Stats): number[] {
return [
MsgTypes.COMMIT_STATS,
...stats.roots,
...stats.classComponents,
...stats.functionComponents,
...stats.fragments,
...stats.forwardRef,
...stats.memo,
...stats.suspense,
...stats.elements,
stats.text,

...stats.keyed,
...stats.unkeyed,
...stats.mixed,

stats.mounts.components,
stats.mounts.elements,
stats.mounts.text,
stats.updates.components,
stats.updates.elements,
stats.updates.text,
stats.unmounts.components,
stats.unmounts.elements,
stats.unmounts.text,

// Single child types
stats.singleChildType.roots,
stats.singleChildType.classComponents,
stats.singleChildType.functionComponents,
stats.singleChildType.fragments,
stats.singleChildType.forwardRef,
stats.singleChildType.memo,
stats.singleChildType.suspense,
stats.singleChildType.elements,
stats.singleChildType.text,
];
export function stats2ops(stats: Stats, out: number[]): void {
out.push(MsgTypes.COMMIT_STATS);

pushStatsChildren(out, stats.roots);
pushStatsChildren(out, stats.classComponents);
pushStatsChildren(out, stats.functionComponents);
pushStatsChildren(out, stats.fragments);
pushStatsChildren(out, stats.forwardRef);
pushStatsChildren(out, stats.memo);
pushStatsChildren(out, stats.suspense);
pushStatsChildren(out, stats.elements);

out.push(stats.text);

pushStatsChildren(out, stats.keyed);
pushStatsChildren(out, stats.unkeyed);
pushStatsChildren(out, stats.mixed);

out.push(stats.mounts.components);
out.push(stats.mounts.elements);
out.push(stats.mounts.text);
out.push(stats.updates.components);
out.push(stats.updates.elements);
out.push(stats.updates.text);
out.push(stats.unmounts.components);
out.push(stats.unmounts.elements);
out.push(stats.unmounts.text);

// Single child types
out.push(stats.singleChildType.roots);
out.push(stats.singleChildType.classComponents);
out.push(stats.singleChildType.functionComponents);
out.push(stats.singleChildType.fragments);
out.push(stats.singleChildType.forwardRef);
out.push(stats.singleChildType.memo);
out.push(stats.singleChildType.suspense);
out.push(stats.singleChildType.elements);
out.push(stats.singleChildType.text);
}

function pushStatsChildren(out: number[], stats: StatsChildren): void {
out.push(stats[0]);
out.push(stats[1]);
out.push(stats[2]);
out.push(stats[3]);
out.push(stats[4]);
}

export interface ParsedStats {
Expand Down

0 comments on commit bcf4417

Please sign in to comment.