Skip to content

fetch-router v1.1.0

Choose a tag to compare

@github-actions github-actions released this 04 Dec 02:27
83d5fe3

Minor Changes

  • The router no longer races middleware and handlers against request.signal. It still stops running middleware and handlers once the request aborts, and router.fetch() still rejects with the abort reason, even if the work in progress fails with its own error, but only after that work settles. Previously router.fetch() and each middleware's await next() rejected the moment the request aborted, while the handler kept running in the background. Middleware cleanup that runs when next() 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, RequestContext lazily creates url, context storage, and bound get/has/set helpers on first use, and synchronous handlers and middleware skip per-layer promise overhead. Routing behavior is unchanged, and routers configured with a custom matcher continue to use it for every request. (#12434)

  • Bumped @remix-run/* dependencies: