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: prevent "MockedRequest" constructor loop #1328

Merged
merged 1 commit into from Jul 14, 2022
Merged

fix: prevent "MockedRequest" constructor loop #1328

merged 1 commit into from Jul 14, 2022

Conversation

95th
Copy link
Collaborator

@95th 95th commented Jul 14, 2022

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 20baac3:

Sandbox Source
MSW React Configuration

if (input instanceof IsomorphicRequest) {
super(input)
} else {
super(input, init)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This call goes to IR constructor in tests but MR constructor in repro.

@95th 95th marked this pull request as ready for review July 14, 2022 10:26
Copy link
Member

@kettanaito kettanaito left a comment

Choose a reason for hiding this comment

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

This looks great. Thank you once more for making this library better, @95th!

The only thing remaining is to depict this issue in a test case.

@kettanaito
Copy link
Member

I can't reproduce this locally at all. I agree that this is a transpilation issue, as the super() call transpiled by TypeScript turns into something like this:

  constructor(input) {
    var _supercall = function () {
      return _supercall(...arguments);
    };

    let init = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

    var __super = function () {
      _supercall(...arguments);
    };

    if (input instanceof import_interceptors.IsomorphicRequest) {
      __super(input);
    } else {
      __super(input, init);
    }

    if (init.id) {
      this.id = init.id;
    }

    this.cache = init.cache || "default";
    this.destination = init.destination || "";
    this.integrity = init.integrity || "";
    this.keepalive = init.keepalive || false;
    this.mode = init.mode || "cors";
    this.priority = init.priority || "auto";
    this.redirect = init.redirect || "follow";
    this.referrer = init.referrer || "";
    this.referrerPolicy = init.referrerPolicy || "no-referrer";
    this.cookies = init.cookies || this.getCookies();
  }

How is this ever a valid transpilation result?

var _supercall = function () {
  return _supercall(...arguments);
};

@kettanaito kettanaito changed the title fix: super call stack overflow fix: prevent "MockedRequest" constructor loop Jul 14, 2022
@kettanaito kettanaito merged commit 6a3f442 into mswjs:main Jul 14, 2022
@kettanaito
Copy link
Member

Released: v0.44.1 🎉

This has been released in v0.44.1!

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.

@95th 95th deleted the x-main branch July 16, 2022 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

msw fails to run on 0.44.0
2 participants