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.
Second attempt to merge #23689. This caused a regression on production the first time we released it. Here's the hotfix revert: #23714.
No known user bad, but it drove our JavaScript error rate high enough to page the DOTD. The reported error was
We can tell the error is happening here, in the
onResize
handler ofInstructionsWithWorkspace
. The issue seems to be that the onResize handler is getting called in a situation where the ref is unbound.code-dot-org/apps/src/templates/instructions/InstructionsWithWorkspace.jsx
Lines 63 to 64 in e97c8f6
After successfully repro'ing this on my local machine and a good deal of trial and error, I discovered that under the original implementation the ref callback was being called on every render, and in maybe 10% of those calls the ref was set to null.
Defining the ref callback once on the component instance instead of within the render method fixes this (the ref callback only happens once when the component mounts). I believe this is because the component sees a new function every time. We've done inline ref callbacks in lots of other places, but in this case it's on
CodeWorkspace
instead of a React-defined DOMComponent, which may explain the different behavior. I wonder if we've found a bug / edge case in the version of React we are using. In any case, I've verified locally that this fixes the issue.