Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auto reload if lazy component fails to load #98

Merged
merged 1 commit into from
Aug 3, 2024
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
31 changes: 19 additions & 12 deletions client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,25 @@
: undefined;
if (typeof boundaryOrFactory !== "string") factory = boundaryOrFactory;
return reactLazy(async () => {
const { default: Component, ErrorFallback, boundary: boundaryOverride } =
await factory!();
const errorBoundaryProps = {
FallbackComponent: ErrorFallback,
} as ErrorBoundaryProps;
if (boundaryOverride) boundary = boundaryOverride;
if (boundary) errorBoundaryProps.boundary = boundaryOverride ?? boundary;
try {
const { default: Component, ErrorFallback, boundary: boundaryOverride } =
await factory!();
const errorBoundaryProps = {
FallbackComponent: ErrorFallback,
} as ErrorBoundaryProps;
if (boundaryOverride) boundary = boundaryOverride;
if (boundary) errorBoundaryProps.boundary = boundaryOverride ?? boundary;

Check warning on line 190 in client.tsx

View check run for this annotation

Codecov / codecov/patch

client.tsx#L183-L190

Added lines #L183 - L190 were not covered by tests

return {
default: errorBoundaryProps.FallbackComponent
? withErrorBoundary(Component, errorBoundaryProps)
: Component,
};
return {
default: errorBoundaryProps.FallbackComponent
? withErrorBoundary(Component, errorBoundaryProps)
: Component,
};
} catch (error) {
const log = getLogger();
log.error("Error loading component", error, { boundary });
window.location.reload();
throw error;
}

Check warning on line 202 in client.tsx

View check run for this annotation

Codecov / codecov/patch

client.tsx#L192-L202

Added lines #L192 - L202 were not covered by tests
});
}
2 changes: 1 addition & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"@std/fs": "jsr:@std/fs@0",
"@std/log": "jsr:@std/log@0",
"@std/path": "jsr:@std/path@1",
"@std/testing": "jsr:@std/testing@0",
"@std/testing": "jsr:@std/testing@1",
"esbuild": "npm:[email protected]",
"react": "npm:react@18",
"@types/react": "npm:@types/react@18",
Expand Down
54 changes: 33 additions & 21 deletions deno.lock

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

2 changes: 1 addition & 1 deletion example/deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"@std/fs": "jsr:@std/fs@0",
"@std/log": "jsr:@std/log@0",
"@std/path": "jsr:@std/path@1",
"@std/testing": "jsr:@std/testing@0",
"@std/testing": "jsr:@std/testing@1",
"esbuild": "npm:[email protected]",
"react": "npm:react@18",
"@types/react": "npm:@types/react@18",
Expand Down
Loading