Skip to content

Commit

Permalink
fix(define-remix-app): apply navigation method when starting from an …
Browse files Browse the repository at this point in the history
…error boundary (#1197)
  • Loading branch information
PeterShershov authored Sep 25, 2024
1 parent b4a8f77 commit 6701055
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
34 changes: 24 additions & 10 deletions packages/define-remix-app/src/manifest-to-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,9 @@ function lazyCompAndLoader(
ErrorBoundary?: React.ComponentType;
};
return {
default: () => {
if (moduleWithComp.ErrorBoundary) {
onCaughtError({ filePath, exportName: 'ErrorBoundary' });
return <moduleWithComp.ErrorBoundary />;
}
if (!isRootFile) {
throw new Error(`ErrorBoundary not found at ${filePath}`);
}
return <div>error boundary not found at {filePath}</div>;
},
default: () => (
<ErrorPage filePath={filePath} moduleWithComp={moduleWithComp} onCaughtError={onCaughtError} />
),
};
})
: undefined;
Expand Down Expand Up @@ -343,3 +336,24 @@ function useDispatcher<T>(dispatcher: Dispatcher<T>) {
}, [dispatcher]);
return state;
}

function ErrorPage({
moduleWithComp,
filePath,
onCaughtError,
}: {
moduleWithComp: {
ErrorBoundary?: React.ComponentType;
};
onCaughtError: ErrorReporter;
filePath: string;
}) {
navigation.setNavigateFunction(useNavigate());

if (moduleWithComp.ErrorBoundary) {
onCaughtError({ filePath, exportName: 'ErrorBoundary' });
return <moduleWithComp.ErrorBoundary />;
}

return <div>error boundary not found at {filePath}</div>;
}
2 changes: 1 addition & 1 deletion packages/define-remix-app/src/page-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ return params;
const ${compIdentifier} = () => {
const params = useLoaderData<typeof loader>();
return <div>
${[...varNames].map((name) => `<div>${clearJsxSpecialCharactersFromText(name)}: {params["${name}}"]</div>`).join('\n')}
${[...varNames].map((name) => `<div>${clearJsxSpecialCharactersFromText(name)}: {params["${name}"]}</div>`).join('\n')}
</div>;
};
export default ${compIdentifier};
Expand Down

0 comments on commit 6701055

Please sign in to comment.