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

Remove instanceof check for DeferredData #10247

Merged
merged 2 commits into from
Mar 22, 2023
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
5 changes: 5 additions & 0 deletions .changeset/rotten-waves-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/router": patch
---

Remove `instanceof` check for `DeferredData` to be resiliant to ESM/CJS boundaries in SSR bundling scenarios
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
},
"filesize": {
"packages/router/dist/router.umd.min.js": {
"none": "43.1 kB"
"none": "43.3 kB"
},
"packages/react-router/dist/react-router.production.min.js": {
"none": "13 kB"
Expand Down
14 changes: 13 additions & 1 deletion packages/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3486,7 +3486,7 @@ async function callLoaderOrAction(
return { type: resultType, error: result };
}

if (result instanceof DeferredData) {
if (isDeferredData(result)) {
return {
type: ResultType.deferred,
deferredData: result,
Expand Down Expand Up @@ -3856,6 +3856,18 @@ function isRedirectResult(result?: DataResult): result is RedirectResult {
return (result && result.type) === ResultType.redirect;
}

export function isDeferredData(value: any): value is DeferredData {
let deferred: DeferredData = value;
return (
deferred &&
typeof deferred === "object" &&
typeof deferred.data === "object" &&
typeof deferred.subscribe === "function" &&
typeof deferred.cancel === "function" &&
typeof deferred.resolveData === "function"
);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied the same function Remix uses


function isResponse(value: any): value is Response {
return (
value != null &&
Expand Down