Skip to content

Commit 375dae9

Browse files
authored
chore(browser): ban enum usage (#3258)
* chore(browser): ban enum usage they compile to overly bloated javascript * Replace rrweb-types enums with const objects
1 parent bab5f3a commit 375dae9

File tree

3 files changed

+116
-101
lines changed

3 files changed

+116
-101
lines changed

packages/browser/.eslintrc.cjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ module.exports = {
44
files: './src/**/*',
55
rules: {
66
'no-restricted-globals': ['error', 'document', 'window'],
7+
'no-restricted-syntax': [
8+
'error',
9+
{
10+
selector: 'TSEnumDeclaration',
11+
message:
12+
'Enums add significant bundle bloat. Use a const object with `as const` and a type union instead. Example: `const Foo = { A: "a", B: "b" } as const; type Foo = (typeof Foo)[keyof typeof Foo];`',
13+
},
14+
],
715
},
816
parserOptions: {
917
ecmaVersion: 2018,

packages/browser/src/extensions/replay/external/lazy-loaded-session-recorder.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export interface SnapshotBuffer {
126126
windowId: string
127127
}
128128

129-
const ACTIVE_SOURCES = [
129+
const ACTIVE_SOURCES: IncrementalSource[] = [
130130
IncrementalSource.MouseMove,
131131
IncrementalSource.MouseInteraction,
132132
IncrementalSource.Scroll,
@@ -152,12 +152,12 @@ function getRRWebRecord(): rrwebRecordType | undefined {
152152
}
153153

154154
export type compressedFullSnapshotEvent = {
155-
type: EventType.FullSnapshot
155+
type: typeof EventType.FullSnapshot
156156
data: string
157157
}
158158

159159
export type compressedIncrementalSnapshotEvent = {
160-
type: EventType.IncrementalSnapshot
160+
type: typeof EventType.IncrementalSnapshot
161161
data: {
162162
source: IncrementalSource
163163
texts: string
@@ -168,9 +168,9 @@ export type compressedIncrementalSnapshotEvent = {
168168
}
169169

170170
export type compressedIncrementalStyleSnapshotEvent = {
171-
type: EventType.IncrementalSnapshot
171+
type: typeof EventType.IncrementalSnapshot
172172
data: {
173-
source: IncrementalSource.StyleSheetRule
173+
source: typeof IncrementalSource.StyleSheetRule
174174
id?: number
175175
styleId?: number
176176
replace?: string

0 commit comments

Comments
 (0)