Skip to content

Commit 32befda

Browse files
authored
fix(remix): Guard against missing default export for server instrument (#8909)
Fixes #8904 I don't know enough about remix to know if/when this can actually happen, but doesn't hurt to guard anyhow!
1 parent 63f342c commit 32befda

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

packages/remix/src/utils/instrumentServer.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,18 +421,21 @@ export function instrumentBuild(build: ServerBuild): ServerBuild {
421421
// Because the build can change between build and runtime.
422422
// So if there is a new `loader` or`action` or `documentRequest` after build.
423423
// We should be able to wrap them, as they may not be wrapped before.
424-
if (!(wrappedEntry.module.default as WrappedFunction).__sentry_original__) {
424+
const defaultExport = wrappedEntry.module.default as undefined | WrappedFunction;
425+
if (defaultExport && !defaultExport.__sentry_original__) {
425426
fill(wrappedEntry.module, 'default', makeWrappedDocumentRequestFunction);
426427
}
427428

428429
for (const [id, route] of Object.entries(build.routes)) {
429430
const wrappedRoute = { ...route, module: { ...route.module } };
430431

431-
if (wrappedRoute.module.action && !(wrappedRoute.module.action as WrappedFunction).__sentry_original__) {
432+
const routeAction = wrappedRoute.module.action as undefined | WrappedFunction;
433+
if (routeAction && !routeAction.__sentry_original__) {
432434
fill(wrappedRoute.module, 'action', makeWrappedAction(id));
433435
}
434436

435-
if (wrappedRoute.module.loader && !(wrappedRoute.module.loader as WrappedFunction).__sentry_original__) {
437+
const routeLoader = wrappedRoute.module.loader as undefined | WrappedFunction;
438+
if (routeLoader && !routeLoader.__sentry_original__) {
436439
fill(wrappedRoute.module, 'loader', makeWrappedLoader(id));
437440
}
438441

0 commit comments

Comments
 (0)