Skip to content

Commit 2aaee62

Browse files
authored
fix: remove componentStack attachment override (#22)
1 parent f2a1095 commit 2aaee62

6 files changed

Lines changed: 13 additions & 65 deletions

File tree

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"author": "zmrl",
3737
"license": "MIT",
3838
"dependencies": {
39-
"bugsplat": "^9.1.0"
39+
"bugsplat": "^9.1.1"
4040
},
4141
"devDependencies": {
4242
"@bugsplat/js-api-client": "^2.0.0",

spec/ErrorBoundary.spec.tsx

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ describe('<ErrorBoundary />', () => {
152152
await waitFor(() => expect(mockPost).toHaveBeenCalledTimes(1));
153153
});
154154

155-
it('should attach componentStack as a text/plain Blob by default', async () => {
155+
it('should attach componentStack as a Blob', async () => {
156156
render(
157157
<ErrorBoundary scope={scope} fallback={BasicFallback}>
158158
<BlowUp />
@@ -169,24 +169,6 @@ describe('<ErrorBoundary />', () => {
169169
expect(attachment.data.type).toBe('text/plain');
170170
});
171171

172-
it('honors scope.getCreateComponentStackAttachment() when provided', async () => {
173-
const customAttachment = { filename: 'componentStack.txt', data: 'CUSTOM' };
174-
const customBuilder = jest.fn(() => customAttachment);
175-
const scopeWithBuilder = new Scope(bugSplat, customBuilder);
176-
177-
render(
178-
<ErrorBoundary scope={scopeWithBuilder} fallback={BasicFallback}>
179-
<BlowUp />
180-
</ErrorBoundary>
181-
);
182-
183-
await waitFor(() => expect(mockPost).toHaveBeenCalledTimes(1));
184-
185-
expect(customBuilder).toHaveBeenCalledWith(expect.stringContaining('BlowUp'));
186-
const [, options] = mockPost.mock.calls[0];
187-
expect(options.attachments).toEqual([customAttachment]);
188-
});
189-
190172
it('should call beforePost', async () => {
191173
render(
192174
<ErrorBoundary

src/ErrorBoundary.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
type BugSplat,
3-
type BugSplatAttachment,
43
type BugSplatResponse,
54
} from 'bugsplat';
65
import {
@@ -11,8 +10,7 @@ import {
1110
type ReactElement,
1211
type ReactNode,
1312
} from 'react';
14-
import { appScope } from './appScope';
15-
import type { Scope } from './scope';
13+
import { getBugSplat } from './appScope';
1614

1715
/**
1816
* Shallowly compare two arrays to determine if they are different.
@@ -139,7 +137,7 @@ interface InternalErrorBoundaryProps {
139137
* to pass their own scope that will inject the client for use by
140138
* ErrorBoundary.
141139
*/
142-
scope: Pick<Scope, 'getClient' | 'getCreateComponentStackAttachment'>;
140+
scope: { getClient(): BugSplat | null };
143141
}
144142

145143
export type ErrorBoundaryProps = JSX.LibraryManagedAttributes<
@@ -199,7 +197,7 @@ export class ErrorBoundary extends Component<
199197
onResetKeysChange: noop,
200198
onUnmount: noop,
201199
disablePost: false,
202-
scope: appScope,
200+
scope: { getClient: getBugSplat },
203201
};
204202

205203
state = INITIAL_STATE;
@@ -247,7 +245,7 @@ export class ErrorBoundary extends Component<
247245

248246
return client.post(error, {
249247
attachments: componentStack
250-
? [scope.getCreateComponentStackAttachment()(componentStack)]
248+
? [{ filename: 'componentStack.txt', data: new Blob([componentStack], { type: 'text/plain' }) }]
251249
: [],
252250
});
253251
}

src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export type {
77

88
export * from './appScope';
99
export * from './ErrorBoundary';
10-
export * from './scope';
1110
export * from './useErrorHandler';
1211
export * from './useFeedback';
1312
export * from './withErrorBoundary';

src/scope.ts

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,10 @@
1-
import type { BugSplat, BugSplatAttachment } from 'bugsplat';
1+
import type { BugSplat } from 'bugsplat';
22

33
/**
4-
* Builds the componentStack attachment for ErrorBoundary posts.
5-
*/
6-
export type CreateComponentStackAttachment = (
7-
componentStack: string
8-
) => BugSplatAttachment;
9-
10-
/**
11-
* Default builder — wraps the stack in a `text/plain` `Blob`.
12-
*/
13-
export const defaultCreateComponentStackAttachment: CreateComponentStackAttachment = (
14-
componentStack
15-
) => ({
16-
filename: 'componentStack.txt',
17-
data: new Blob([componentStack], { type: 'text/plain' }),
18-
});
19-
20-
/**
21-
* Encapsulate BugSplat client instance and scope-level overrides.
4+
* Encapsulate BugSplat client instance
225
*/
236
export class Scope {
24-
constructor(
25-
private client: BugSplat | null = null,
26-
private createComponentStackAttachment: CreateComponentStackAttachment = defaultCreateComponentStackAttachment
27-
) {}
7+
constructor(private client: BugSplat | null = null) {}
288

299
/**
3010
* @returns BugSplat client instance or null if unset
@@ -36,15 +16,4 @@ export class Scope {
3616
setClient(client: BugSplat) {
3717
this.client = client;
3818
}
39-
40-
/**
41-
* @returns the current componentStack attachment builder
42-
*/
43-
getCreateComponentStackAttachment() {
44-
return this.createComponentStackAttachment;
45-
}
46-
47-
setCreateComponentStackAttachment(fn: CreateComponentStackAttachment) {
48-
this.createComponentStackAttachment = fn;
49-
}
5019
}

0 commit comments

Comments
 (0)