Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this seems to break for everyone outside of next.js so I'm wondering what next.js is doing to have to trigger the load event manually?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
readyState
code is here to handle cross browser differencesforceUpdate
to render and trigger the load eventreadyState
and instead will update contents on iframe loadIf we introduce a third call then chromium based browsers throw as it tries to render the contents before srcdoc has injected it (srcdoc is async) so there may be a timing issue here. I'm unsure why this works in next.js based apps in chromium based browsers??
Firefox works fine with as this addition is not a codepath firefox reaches
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could definitely see this being an async timing issue. My
initialContent
is fairly large and includes external stylesheets like FontAwesome and stuff, which I could see causing some timing issue if it takes too long to load, especially on a page refresh where external resources might have to reload but other things might be cached and thus trigger things in a different order, but randomly on a later refresh the timing is off in the other direction and it works fine.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, do you think you could share a test case with your intitialContent?
In some further exploring it seems the
addEventListener
incompnentDidMount
is superfluous and actually triggers a double load event in firefox.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would think you could just take @baptisteArno 's test case and apply my initialContent over the top of it.
You can also try using my repo https://github.com/naturalcrit/homebrewery and just update react-frame-component to see it break. Unfortunately I'm having trouble isolating a smaller version of the app because it's inherited from someone else and I don't know all the ins and outs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR breaks, see the github action tests. It complains about the
mountTarget
being null as theinititalContent
provided to the iframe viasrcdoc
hasn't rendered yet.It might be that next.js has aggressive caching and that's why it manifests itself there more than elsewhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
onLoad
property on the iframe.... should it beonload
, lowercase? https://www.w3schools.com/jsref/event_onload.aspThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's a react thing it'll get normalised to
onload
when it's written to the DOMThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha. Like className to class. Ok.
Another possibility. Seems like if a page is in cache, onLoad can potentially trigger right away, before the handler is even assigned to onLoad.
https://stackoverflow.com/questions/19917436/window-onload-not-running-on-page-refresh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks seems like there could be something related there. This is issue is hard to diagnose as it hasn't been easy for me to reproduce if someone could create a codesandbox.io where it is easily recreated it would help a lot.