-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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 future flag to throw request.signal.reason for aborted requests #11104
Changes from 2 commits
beda7bf
4e43b7e
9463fb5
72cf963
e7ce895
15b6ce2
219def2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@remix-run/router": minor | ||
--- | ||
|
||
Add `createStaticHandler` `future.v7_throwAbortReason` flag to instead throw `request.signal.reason` when a request is aborted instead of our own custom `new Error()` with a message such as `query() call aborted`/`queryRoute() call aborted`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2823,6 +2823,7 @@ export const UNSAFE_DEFERRED_SYMBOL = Symbol("deferred"); | |
*/ | ||
export interface StaticHandlerFutureConfig { | ||
v7_relativeSplatPath: boolean; | ||
v7_throwAbortReason: boolean; | ||
} | ||
|
||
export interface CreateStaticHandlerOptions { | ||
|
@@ -2861,6 +2862,7 @@ export function createStaticHandler( | |
// Config driven behavior flags | ||
let future: StaticHandlerFutureConfig = { | ||
v7_relativeSplatPath: false, | ||
v7_throwAbortReason: false, | ||
...(opts ? opts.future : null), | ||
}; | ||
|
||
|
@@ -3130,10 +3132,7 @@ export function createStaticHandler( | |
); | ||
|
||
if (request.signal.aborted) { | ||
let method = isRouteRequest ? "queryRoute" : "query"; | ||
throw new Error( | ||
`${method}() call aborted: ${request.method} ${request.url}` | ||
); | ||
throwStaticHandlerAbortedError(request, isRouteRequest, future); | ||
} | ||
} | ||
|
||
|
@@ -3301,10 +3300,7 @@ export function createStaticHandler( | |
]); | ||
|
||
if (request.signal.aborted) { | ||
let method = isRouteRequest ? "queryRoute" : "query"; | ||
throw new Error( | ||
`${method}() call aborted: ${request.method} ${request.url}` | ||
); | ||
throwStaticHandlerAbortedError(request, isRouteRequest, future); | ||
} | ||
|
||
// Process and commit output from loaders | ||
|
@@ -3369,6 +3365,21 @@ export function getStaticContextFromError( | |
return newContext; | ||
} | ||
|
||
function throwStaticHandlerAbortedError( | ||
request: Request, | ||
isRouteRequest: boolean, | ||
future: StaticHandlerFutureConfig | ||
) { | ||
let method = isRouteRequest ? "queryRoute" : "query"; | ||
if (future.v7_throwAbortReason && request.signal.reason !== undefined) { | ||
throw request.signal.reason; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only downside I see here is that we lose the request method/URL that we include in the custom error, but I think if folks need that then they should be passing a custom reason when they call |
||
} else { | ||
throw new Error( | ||
`${method}() call aborted: ${request.method} ${request.url}` | ||
); | ||
} | ||
} | ||
|
||
function isSubmissionNavigation( | ||
opts: BaseNavigateOrFetchOptions | ||
): opts is SubmissionNavigateOptions { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth calling out - this could be an issue in Remix apps that still use the polyfills if we wanted to use a custom
reason