react: Bug:
renders twice in firefox with react 18
React version: 18.2.0
Steps To Reproduce
- Insert a tag
<img/>with src - Go to Firefox inspect tool to the tab network
- Reload the page and watch image request in network
Link to code example: https://codesandbox.io/s/unruffled-jerry-9hli44?file=/src/App.js
The current behavior
There are two request for image in firefox, image renders twice

The expected behavior
There is one request and one render in firefox
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 19
- Comments: 20
There is, check https://codesandbox.io/s/unruffled-jerry-9hli44?file=/src/index.js On Edge and Firefox I still getting 2 requests, disabling strict-mode it stops.
It really is an issue. Where can we find the root cause of this problem?
We are observing the same behaviour. Firefox 115, Ubuntu Linux 23.04 and macOs. Unable to test on Windows yet.
Here is some details.
The first request is initiated in react-dom.development.js, line 855:
Here is the stack trace.
The second request is initiated here:
node, in the first snippet, anddomElement, in the 2nd, are the very same variable: the real<img>DOM node.The point is the browser is replacing the source of the imgage twice. If the first request has not been completed when the
srcattribute is set the second time, the browser aborts the first request, leading to theNS_BINDING_ABORTEDerror. This occurs despite the src value is the same both time.Note that the src is always converted to a fully qualified URL (have a look : https://github.com/facebook/react/commit/f0dd459e0d97081cb3c313ec52285e3e422f8dbf):
This behaviour has been introduced in https://github.com/facebook/react/commit/086fa8ee2f80f0dc34b7d145be72f9843fca975d
Using Chromium, the request is only initated once, at the very end of the process.
It really happens, even on Chrome/Edge. But I think this is due to StrictMode. Could please try deleting StrictMode on
index.js?It will look like this.
On StrictMode react render twice. https://reactjs.org/docs/strict-mode.html
@MiguelMachado-dev, Just check this example (without
StrictMode): https://codesandbox.io/s/goofy-stonebraker-pf0wg7?file=/src/index.js (https://pf0wg7.csb.app/)And there is screenshot with two requests:
What i’m doing wrong?
it doesn’t help, in my example in codesandbox I tried to remove StrictMode, but the behavior is the same, there are two requests in network tab Аnd on Chrome, if you open this https://c1i5n8.csb.app/ there are no two requests in network tab