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

fix: do not treat static asset requests as unhandled by default #2440

Merged
merged 8 commits into from
Feb 24, 2025

Conversation

kettanaito
Copy link
Member

@kettanaito kettanaito commented Feb 24, 2025

By default, MSW catches all requests that go through the Service Worker. This includes all the static assets too, like CSS or HTML or fonts. Treating them as unhandled rarely makes sense.

import { isCommonAssetRequest } from 'msw'

Changes

  • Export the isCommonAssetRequest utility function from msw.
  • Change the default behavior of onUnhandledRequest to exclude common static assets before applying string behaviors like 'warn'.
  • Allow opting out from the default behavior if you provide a function as the value of onUnhandledRequest. If you do, then you have to import and use isCommonAssetRequest() manually to get the default behavior back. This is intended for behavior customization.

@kettanaito kettanaito changed the title fix: export isAssetRequest utility fix: do not treat static asset requests as unhandled by default Feb 24, 2025
@kettanaito kettanaito added the DX label Feb 24, 2025
@kettanaito kettanaito marked this pull request as ready for review February 24, 2025 13:22
@kettanaito kettanaito merged commit eb45e7a into main Feb 24, 2025
18 checks passed
@kettanaito kettanaito deleted the fix/asset-requests branch February 24, 2025 13:23
@kettanaito
Copy link
Member Author

Released: v2.7.3 🎉

This has been released in v2.7.3!

Make sure to always update to the latest version (npm i msw@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant