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

Bug: Why does React need to replay beginwork when an exception occurs #25041

Closed
lizuncong opened this issue Aug 4, 2022 · 2 comments
Closed
Labels
Resolution: Stale Automatically closed due to inactivity Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@lizuncong
Copy link

React version: React17.0.1

Sorry, I am curious why the beginWork function needs to be executed repeatedly if an exception is thrown in the beginWork function. In fact, we can simplify the exception catching logic of the beginWork function

Maybe this would work too

      let caughtError = null;

      function invokeGuardedCallback(func) {
        const evt = document.createEvent("Event");
        const evtType = "react-invokeguardedcallback";
        const fakeNode = document.createElement("react");
        let child; // keep the result of beginWork in the child variable

        function callCallback() {
          fakeNode.removeEventListener(evtType, callCallback, false);
          child = func(); // keep the result of func
        }

        function handleWindowError(event) {
          caughtError = event.error;
        }

        window.addEventListener("error", handleWindowError);
        fakeNode.addEventListener(evtType, callCallback, false);

        evt.initEvent(evtType, false, false);
        fakeNode.dispatchEvent(evt);

        window.removeEventListener("error", handleWindowError);
        return child; // return it
      }

      function beginWork() {
        return "child";
      }
      beginWork$1 = function (current, unitOfWork, lanes) {
        const child = invokeGuardedCallback(beginWork);
        if (hasCaughtError()) {
          var replayError = clearCaughtError();
          throw replayError;
        }
        console.log("next..", child);
        return child;
      };
      beginWork$1();
@lizuncong lizuncong added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Aug 4, 2022
Copy link

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

@github-actions github-actions bot added the Resolution: Stale Automatically closed due to inactivity label Apr 10, 2024
Copy link

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Stale Automatically closed due to inactivity Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

1 participant