Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"author": "zmrl",
"license": "MIT",
"dependencies": {
"bugsplat": "^9.1.0"
"bugsplat": "^9.1.1"
},
"devDependencies": {
"@bugsplat/js-api-client": "^2.0.0",
Expand Down
20 changes: 1 addition & 19 deletions spec/ErrorBoundary.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ describe('<ErrorBoundary />', () => {
await waitFor(() => expect(mockPost).toHaveBeenCalledTimes(1));
});

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

it('honors scope.getCreateComponentStackAttachment() when provided', async () => {
const customAttachment = { filename: 'componentStack.txt', data: 'CUSTOM' };
const customBuilder = jest.fn(() => customAttachment);
const scopeWithBuilder = new Scope(bugSplat, customBuilder);

render(
<ErrorBoundary scope={scopeWithBuilder} fallback={BasicFallback}>
<BlowUp />
</ErrorBoundary>
);

await waitFor(() => expect(mockPost).toHaveBeenCalledTimes(1));

expect(customBuilder).toHaveBeenCalledWith(expect.stringContaining('BlowUp'));
const [, options] = mockPost.mock.calls[0];
expect(options.attachments).toEqual([customAttachment]);
});

it('should call beforePost', async () => {
render(
<ErrorBoundary
Expand Down
10 changes: 4 additions & 6 deletions src/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
type BugSplat,
type BugSplatAttachment,
type BugSplatResponse,
} from 'bugsplat';
import {
Expand All @@ -11,8 +10,7 @@ import {
type ReactElement,
type ReactNode,
} from 'react';
import { appScope } from './appScope';
import type { Scope } from './scope';
import { getBugSplat } from './appScope';

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

export type ErrorBoundaryProps = JSX.LibraryManagedAttributes<
Expand Down Expand Up @@ -199,7 +197,7 @@ export class ErrorBoundary extends Component<
onResetKeysChange: noop,
onUnmount: noop,
disablePost: false,
scope: appScope,
scope: { getClient: getBugSplat },
};

state = INITIAL_STATE;
Expand Down Expand Up @@ -247,7 +245,7 @@ export class ErrorBoundary extends Component<

return client.post(error, {
attachments: componentStack
? [scope.getCreateComponentStackAttachment()(componentStack)]
? [{ filename: 'componentStack.txt', data: new Blob([componentStack], { type: 'text/plain' }) }]
: [],
});
}
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export type {

export * from './appScope';
Comment thread
bobbyg603 marked this conversation as resolved.
export * from './ErrorBoundary';
export * from './scope';
export * from './useErrorHandler';
export * from './useFeedback';
export * from './withErrorBoundary';
37 changes: 3 additions & 34 deletions src/scope.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,10 @@
import type { BugSplat, BugSplatAttachment } from 'bugsplat';
import type { BugSplat } from 'bugsplat';

/**
* Builds the componentStack attachment for ErrorBoundary posts.
*/
export type CreateComponentStackAttachment = (
componentStack: string
) => BugSplatAttachment;

/**
* Default builder — wraps the stack in a `text/plain` `Blob`.
*/
export const defaultCreateComponentStackAttachment: CreateComponentStackAttachment = (
componentStack
) => ({
filename: 'componentStack.txt',
data: new Blob([componentStack], { type: 'text/plain' }),
});

/**
* Encapsulate BugSplat client instance and scope-level overrides.
* Encapsulate BugSplat client instance
*/
export class Scope {
constructor(
private client: BugSplat | null = null,
private createComponentStackAttachment: CreateComponentStackAttachment = defaultCreateComponentStackAttachment
) {}
constructor(private client: BugSplat | null = null) {}

/**
* @returns BugSplat client instance or null if unset
Expand All @@ -36,15 +16,4 @@ export class Scope {
setClient(client: BugSplat) {
this.client = client;
}

/**
* @returns the current componentStack attachment builder
*/
getCreateComponentStackAttachment() {
return this.createComponentStackAttachment;
}

setCreateComponentStackAttachment(fn: CreateComponentStackAttachment) {
this.createComponentStackAttachment = fn;
}
}
Loading