Skip to content

Hot loading loses effect after modifying the window.fetch method. #13443

@renzhaoz

Description

@renzhaoz

Describe the bug

Hot loading loses effect after modifying the window.fetch method.

Did you try recovering your dependencies?

(Write your answer here.)YES

Which terms did you search for in User Guide?

(Write your answer here if relevant.)

Environment

windows
package info:

    "@testing-library/jest-dom": "^5.17.0",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-scripts": "5.0.1",

Steps to reproduce

(Write your steps here:)

  1. npm install create-react-app -g
  2. npx create-react-app myapp
  3. Add Authorization info to http request, then import this file in App.js, like this:
   import CloudUtils from './CloudUtils';

const oldFetch = fetch;

const newFetch = (url, options) => {
  const token = CloudUtils.getToken();
  const headers = options.headers || new Headers();
  headers.append('Authorization', `bearer ${token}`);
  options.headers = headers;

  return oldFetch(`${url}`, options);
};

if (window) {
  window.fetch = newFetch;
  window.oldFetch = oldFetch;
}

  1. Hot reload not work now!

Expected behavior

(Write what you thought would happen.)
Hot reload not work!

Actual behavior

(Write what happened. Please add screenshots!)

Reproducible demo

(Paste the link to an example project and exact instructions to reproduce the issue.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions