Fix bug in Safari when calculating text coords of hidden nodes #3
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.
Hi @marijnh, while working on a component which uses CodeMirror I noticed some errors being raised in Safari v14.0.3.
It doesn't seem to be a fatal issue, but logs a
TypeError: undefined is not an object (evaluating 'h.width')
.Looking into it a bit more, it seems that the issue is related to how I render the
parent
DOM element housing the editor.Depending on the user supplied prop, the CodeMirror instance can start hidden, and later toggled to be seen.
The component can be seen here
What happens is that
range.getClientRects()
(linked below) returns an empty array (see screenshot from safari stopped at the breakpoint. Apologies for the minified source code). Trying to access this array with an index then returnsundefined
.view/src/inlineview.ts
Lines 146 to 148 in 1b92b55
A simple fix in this case was to check the existence of the
rect
variable before accessing thewidth
property. However I couldn't quite decide what should happen regarding the fallback on line 148.There's a bit of type coercion going on, and in this case the function might return
undefined
I think. Should I stub aRect
object with zero dimensions in this case?Please let me know if you have any suggested changes, if this PR is out of scope, or if a rambled too much and failed to explain the issue.
Thanks for your time!