-
Notifications
You must be signed in to change notification settings - Fork 23
fix: use window.devicePixelRatio to calculate default pixel ratio #1382
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
base: main
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughThese changes simplify device pixel ratio calculation in the device utility and refactor coordinate mapping in the VFXItem class to use canvas bounding client rect dimensions instead of renderer-derived values, with an added pixel-to-world translation method. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@packages/effects-core/src/vfx-item.ts`:
- Around line 505-523: Both setPositionByPixel and translateByPixel can divide
by canvas width/height and produce NaN when the canvas size is zero; add a guard
after reading const { width, height } =
this.composition.getEngine().canvas.getBoundingClientRect() in both methods to
early-return if width === 0 || height === 0 (or if either is falsy), preventing
math operations that would corrupt this.transform; keep the existing logic
otherwise and reference the methods setPositionByPixel and translateByPixel and
the call to getBoundingClientRect() when applying the guard.
🧹 Nitpick comments (1)
packages/effects-core/src/utils/device.ts (1)
2-3: Consider reusingcanUseBOMfor the window check.Keeps BOM guards consistent within this module and centralizes the environment check.
♻️ Suggested tweak
-export function getPixelRatio (): number { - if (typeof window === 'object') { +export function getPixelRatio (): number { + if (canUseBOM) { return Math.min(2, window.devicePixelRatio || 1); }
Summary by CodeRabbit
Release Notes
Bug Fixes
New Features
✏️ Tip: You can customize this high-level summary in your review settings.