Be robust against Firefox sometimes returning a zero-width rect #75

Closed
DrRataplan wants to merge 1 commit from main into main
DrRataplan commented 2025-12-05 14:48:58 +01:00 (Migrated from github.com)

This sometimes occurs in Firefox when a codemirror view is invisible initially. The rect does have a usable height, but the width is zero. This causes a set of Infinity and NaN values later in the flow.

Be more robust against that: default it to a sensible value.

I manually verified this fixes https://github.com/codemirror/dev/issues/1642. Since this codeflow is only hit in a case where everything errors out later anyway I'm quite confident about this fix.

This sometimes occurs in Firefox when a codemirror view is invisible initially. The rect does have a usable height, but the width is zero. This causes a set of Infinity and NaN values later in the flow. Be more robust against that: default it to a sensible value. I manually verified this fixes https://github.com/codemirror/dev/issues/1642. Since this codeflow is only hit in a case where everything errors out later anyway I'm quite confident about this fix.
marijnh commented 2025-12-05 15:48:04 +01:00 (Migrated from github.com)

How about just charWidth = rect && rect.width ? rect.width / 27 : 7, for simplicity?

How about just `charWidth = rect && rect.width ? rect.width / 27 : 7`, for simplicity?
marijnh commented 2025-12-08 21:36:21 +01:00 (Migrated from github.com)

I've merged the simpler patch.

I've merged the simpler patch.
DrRataplan commented 2025-12-09 08:55:44 +01:00 (Migrated from github.com)

Sorry for not responding right away! Thanks so much!

Sorry for not responding right away! Thanks so much!

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
codemirror/view!75
No description provided.