Skip to content

Commit 1c08ec6

Browse files
authored
Remove instanceof check for DeferredData (#10247)
1 parent 97b5c42 commit 1c08ec6

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

.changeset/rotten-waves-fold.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@remix-run/router": patch
3+
---
4+
5+
Remove `instanceof` check for `DeferredData` to be resiliant to ESM/CJS boundaries in SSR bundling scenarios

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
},
106106
"filesize": {
107107
"packages/router/dist/router.umd.min.js": {
108-
"none": "43.1 kB"
108+
"none": "43.3 kB"
109109
},
110110
"packages/react-router/dist/react-router.production.min.js": {
111111
"none": "13 kB"

packages/router/router.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3486,7 +3486,7 @@ async function callLoaderOrAction(
34863486
return { type: resultType, error: result };
34873487
}
34883488

3489-
if (result instanceof DeferredData) {
3489+
if (isDeferredData(result)) {
34903490
return {
34913491
type: ResultType.deferred,
34923492
deferredData: result,
@@ -3856,6 +3856,18 @@ function isRedirectResult(result?: DataResult): result is RedirectResult {
38563856
return (result && result.type) === ResultType.redirect;
38573857
}
38583858

3859+
export function isDeferredData(value: any): value is DeferredData {
3860+
let deferred: DeferredData = value;
3861+
return (
3862+
deferred &&
3863+
typeof deferred === "object" &&
3864+
typeof deferred.data === "object" &&
3865+
typeof deferred.subscribe === "function" &&
3866+
typeof deferred.cancel === "function" &&
3867+
typeof deferred.resolveData === "function"
3868+
);
3869+
}
3870+
38593871
function isResponse(value: any): value is Response {
38603872
return (
38613873
value != null &&

0 commit comments

Comments
 (0)