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 ReactAct flushActQueue error handler #24175

Closed
wants to merge 6 commits into from

Conversation

dev-itsheng
Copy link

Summary

When I read React's code, I noticed a detail:

function flushActQueue(queue) {
  if (__DEV__) {
    if (!isFlushing) {
      // Prevent re-entrance.
      isFlushing = true;
      let i = 0;
      try {
        for (; i < queue.length; i++) {
          let callback = queue[i];
          do {
            callback = callback(true);
          } while (callback !== null);
        }
        queue.length = 0;
      } catch (error) {
        // If something throws, leave the remaining callbacks on the queue.
        queue = queue. slice(i + 1);     // <---------- This code
        throw error;
      } finally {
        isFlushing = false;
      }
    }
  }
}

Note the line queue = queue.slice(i + 1);, which reassigns the parameters in the function. Obviously, this sentence does not work, and the actual "queue" will remain unchanged. .

To achieve the actual effect, there are two methods. The first is to use a method that can modify the value of the array itself, such as queue.splice(0, i + 1). The second is to directly modify the pointer of queue, that is ReactCurrentActQueue.current, I used the second method.

How did you test this change?

I noticed that for ReactAct.js, there is no corresponding test file in the __tests__ folder, so I added one and tested indirectly through the act function exported by this file.

However, due to my environment issues, the tests were not successfully executed locally. The specific reasons are still to be seen, but I decided to commit first, and then use GitHub's CI to check whether the changes took effect.

If the results are not correct, I will continue to improve my code.

Also, there is a small problem, I noticed that there is an AUTHORS file in the root directory of the project, do I need to add this manually?

@facebook-github-bot
Copy link

Hi @dev-itsheng!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@sizebot
Copy link

sizebot commented Mar 27, 2022

Comparing: e7d0053...a2bd5a8

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.min.js = 131.32 kB 131.32 kB = 41.96 kB 41.96 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 136.38 kB 136.38 kB = 43.42 kB 43.42 kB
facebook-www/ReactDOM-prod.classic.js = 432.73 kB 432.73 kB = 79.60 kB 79.60 kB
facebook-www/ReactDOM-prod.modern.js = 417.73 kB 417.73 kB = 77.21 kB 77.22 kB
facebook-www/ReactDOMForked-prod.classic.js = 432.73 kB 432.73 kB = 79.60 kB 79.60 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by 🚫 dangerJS against a2bd5a8

@dev-itsheng
Copy link
Author

There seems to be a problem, wait for me to fix it.

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

Copy link

This pull request has been automatically marked as stale. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize reviewing it yet. Your contribution is very much appreciated.

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

Closing this pull request after a prolonged period of inactivity. If this issue is still present in the latest release, please ask for this pull request to be reopened. Thank you!

@github-actions github-actions bot closed this Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Resolution: Stale Automatically closed due to inactivity
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants