Minor Changes
-
The router no longer races middleware and handlers against
request.signal. It still stops running middleware and handlers once the request aborts, androuter.fetch()still rejects with the abort reason, even if the work in progress fails with its own error, but only after that work settles. Previouslyrouter.fetch()and each middleware'sawait next()rejected the moment the request aborted, while the handler kept running in the background. Middleware cleanup that runs whennext()rejects, such as rolling back a transaction, now runs after the handler finishes. Responses that arrive after the request aborted still have their bodies cancelled. Requests through async handlers and middleware are about a third faster because the router no longer adds an abort listener to async requests or wraps each async layer in another promise. (#12446)Work that should stop when the client disconnects needs the signal passed to it:
router.get(routes.search, async ({ request, url }) => { - let results = await fetch(searchApi(url)) + let results = await fetch(searchApi(url), { signal: request.signal }) return Response.json(await results.json()) })See the decision doc for the reasoning.
Patch Changes
-
createRouter()dispatches requests significantly faster in our benchmarks, especially for static routes and middleware chains. Routes are indexed by request method with a direct lookup for plain static pathnames,RequestContextlazily createsurl, context storage, and boundget/has/sethelpers on first use, and synchronous handlers and middleware skip per-layer promise overhead. Routing behavior is unchanged, and routers configured with a custommatchercontinue to use it for every request. (#12434) -
Bumped
@remix-run/*dependencies: