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: setState is not flushed if an iframe is added in the same tick in Safari #24458

Closed
kh-viewar opened this issue Apr 28, 2022 · 3 comments · Fixed by #24459
Closed

Bug: setState is not flushed if an iframe is added in the same tick in Safari #24458

kh-viewar opened this issue Apr 28, 2022 · 3 comments · Fixed by #24459
Labels
Browser: Safari React 18 Bug reports, questions, and general feedback about React 18 Type: Bug

Comments

@kh-viewar
Copy link

kh-viewar commented Apr 28, 2022

Batched state changes are not flushed if the promise code changes the DOM (= attaching an iframe). Reproduceable with Safari.

React version: 18.1.0

Steps To Reproduce

  1. Open codepen with Safari.
  2. Click "Upload"
  3. => "Spinner" text does not render while Promise is in pending

Link to code example:

https://codepen.io/kh-viewar/pen/wvpVLxM

The current behavior

State changes are not executed.

The expected behavior

State should change to true and render spinner component. After promise is resolved (2 seconds timeout), state should switch back to false and spinner component should unmount.

Original discussion

#24365

@kh-viewar kh-viewar added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Apr 28, 2022
@gaearon
Copy link
Collaborator

gaearon commented Apr 28, 2022

I suspect this might be #22459 (comment) showing its head again. Can you check the issue repros in desktop Safari as well?

@kh-viewar
Copy link
Author

kh-viewar commented Apr 28, 2022

I suspect this might be #22459 (comment) showing its head again. Can you check the issue repros in desktop Safari as well?

Yes, same on Safari Desktop. Will update issue description.

€: Also reproduceable with @next version.

@kh-viewar kh-viewar changed the title Bug: Batched state changes are not flushed if the promise code changes the DOM (mobile devices) Bug: Batched state changes are not flushed if the promise code changes the DOM (Safari) Apr 28, 2022
@gaearon gaearon added Type: Bug Browser: Safari React 18 Bug reports, questions, and general feedback about React 18 and removed Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug labels Apr 28, 2022
@gaearon gaearon changed the title Bug: Batched state changes are not flushed if the promise code changes the DOM (Safari) Bug: setState is not flushed if an iframe is added in the same tick in Safari Apr 28, 2022
@gaearon
Copy link
Collaborator

gaearon commented Apr 28, 2022

Minimal repro.

function App() {
  const [count, setCount] = React.useState(0);

  return (
    <button onClick={() => {
      setCount(c => c + 1);
      document.body.appendChild(document.createElement("iframe"));
    }}>
      {count}
    </button>
  );
};

const rootElement = document.getElementById("app");
const root = ReactDOM.createRoot(rootElement);
root.render(<App />);

Only repros in Safari and only when served over http(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Browser: Safari React 18 Bug reports, questions, and general feedback about React 18 Type: Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants