Skip to content

Commit a20bad9

Browse files
committed
fix: wrap event store in bounded array
1 parent 4c0a9b1 commit a20bad9

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

packages/scan/src/auto.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import "./polyfills";
1+
import './polyfills';
22
// Prioritize bippy side-effect
3-
import "bippy";
3+
import 'bippy';
44

5-
import { IS_CLIENT } from "~web/utils/constants";
6-
import { scan } from "./index";
5+
import { IS_CLIENT } from '~web/utils/constants';
6+
import { scan } from './index';
77

88
if (IS_CLIENT) {
99
scan();
1010
window.reactScan = scan;
1111
}
1212

13-
export * from "./core";
13+
export * from './core';

packages/scan/src/core/notifications/event-tracking.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export type SlowdownEvent = (InteractionEvent | LongRenderPipeline) & {
104104

105105
type ToolbarEventStoreState = {
106106
state: {
107-
events: Array<SlowdownEvent>;
107+
events: BoundedArray<SlowdownEvent>;
108108
};
109109
actions: {
110110
addEvent: (event: SlowdownEvent) => void;
@@ -149,13 +149,15 @@ export const debugEventStore = createStore<{
149149
},
150150
}));
151151

152+
const EVENT_STORE_CAPACITY = 200;
153+
152154
export const toolbarEventStore = createStore<ToolbarEventStoreState>()(
153155
(set, get) => {
154156
const listeners = new Set<(event: SlowdownEvent) => void>();
155157

156158
return {
157159
state: {
158-
events: [],
160+
events: new BoundedArray(EVENT_STORE_CAPACITY),
159161
},
160162

161163
actions: {
@@ -240,7 +242,10 @@ export const toolbarEventStore = createStore<ToolbarEventStoreState>()(
240242

241243
set(() => ({
242244
state: {
243-
events: withRemovedEvents,
245+
events: BoundedArray.fromArray(
246+
withRemovedEvents,
247+
EVENT_STORE_CAPACITY,
248+
),
244249
},
245250
}));
246251
},
@@ -255,7 +260,7 @@ export const toolbarEventStore = createStore<ToolbarEventStoreState>()(
255260
clear: () => {
256261
set({
257262
state: {
258-
events: [],
263+
events: new BoundedArray(EVENT_STORE_CAPACITY),
259264
},
260265
});
261266
},

0 commit comments

Comments
 (0)