-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lexical-utils] Bug Fix: Add feature detection to calculateZoomLevel #6864
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
size-limit report 📦
|
This looks reasonable. Was originally thinking, since the method is used only in 3 places in 'lexical-react', if we have a way to get it out and have at playground level-only, but besides passing an extra argument to the 3 plugins (draggable block, checklist, context menu), dont have anything better. Chrome 128+ already has a pretty decent market share, so Ideally in 6-7 months we can remove the solution we come up with. |
I think we still need it for Safari |
it's in the official spec now, I believe it already works in Safari and according to https://caniuse.com/css-zoom seems ok |
That's just the zoom CSS property and according to that table it's been supported in Chromium since 4 (2010). Running this code in Safari 18.1.1 (macOS) sets NEEDS_MANUAL_ZOOM to true where Firefox and Chromium set it to false. const div = document.createElement('div');
div.style.cssText =
'position: absolute; opacity: 0; width: 100px; left: -1000px;';
document.body.appendChild(div);
const noZoom = div.getBoundingClientRect();
div.style.setProperty('zoom', '2');
NEEDS_MANUAL_ZOOM = div.getBoundingClientRect().width === noZoom.width;
document.body.removeChild(div); |
We don't have any tests that cover this but I think it should be fine. I'm not impacted or interested enough to write e2e for this myself, but if anyone else wants to do that it would be appreciated. |
have added tests-needed label |
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.
is this related to browser zoom? ie ctrl
+ shift
+ +
/-
to zoom in and out
The browser-level zoom behaves correctly already. The problem this fixed is when you embed the editor in anything that uses CSS Zoom and the clickable regions would respect the browser-level zoom, but not the CSS zoom, despite resizing correctly, which is used for content reflow rather than transform, also the CSS Zoom didn't propagate to iframe tags prior to the Chromium-level fix. |
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.
Appreciate the quick help on this!
Description
Add feature detection to
calculateZoomLevel
in situations when we are not sure if the browser implements standardized CSS zoom. We still assume that Firefox does, but since only Chrome >= 128 implements it and Safari doesn't implement it yet we use feature detection (creating a div in the document but off-screen, measuring it with and without zoom, then removing it). It's measured twice in case there's a zoom on the body which could cancel out a static measurement.Closes #6863
Test plan
Before
Insert relevant screenshots/recordings/automated-tests
After
Insert relevant screenshots/recordings/automated-tests