-
Notifications
You must be signed in to change notification settings - Fork 50.4k
Description
Recently I detected a problem using React in SSR. Maybe is quite obvious, but all the JavaScript events that are fired before the JavaScript is loaded, are lost...
This is something normal. The JS is not there yet... Ok. However, I expect to have some utility to do some exceptions.
I'm going to try to explain my case:
I'm using an image, and in the event onError, I want to change the src to render a fallback image.
function Img(props) {
return (
<img {...props} onError={e => { e.target.src = fallbackSrc } } />
)
}Nevertheless, this code loaded from SSR, is working "sometimes"... I guess that this "sometimes" is because if the event is fired before the client side hydration. Is not catched by my JS. And the e => e.target.src = fallbackSrc is never executed. However, if the JS is loaded faster than the onError event, is catched, and is rendering the fallback image as I expected.
I want to propose some utility to do sometimes some exceptions, and render the JS inline on the first render. Perhaps, adding some extra config in ReactDOM.hydrate? I dunno...
Or maybe someone can help me providing any tip in order to fix this?