-
Notifications
You must be signed in to change notification settings - Fork 16
fix(core): shadow-aware incremental damage bounds #49
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
packages/core/src/renderer/renderToDrawlist/damageBounds.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import type { Rect } from "../../layout/types.js"; | ||
| import type { RuntimeInstance } from "../../runtime/commit.js"; | ||
| import { getRectWithShadow } from "../shadow.js"; | ||
|
|
||
| type BoxShadowProps = Readonly<{ | ||
| shadow?: unknown; | ||
| }>; | ||
|
|
||
| function readShadowOffset(raw: unknown, fallback: number): number { | ||
| if (typeof raw !== "number" || !Number.isFinite(raw)) { | ||
| return fallback; | ||
| } | ||
| const value = Math.trunc(raw); | ||
| return value <= 0 ? 0 : value; | ||
| } | ||
|
|
||
| function resolveShadowOffsets( | ||
| shadow: unknown, | ||
| ): Readonly<{ offsetX: number; offsetY: number }> | null { | ||
| if (shadow !== true && (shadow === false || shadow === undefined || shadow === null)) { | ||
| return null; | ||
| } | ||
| if (shadow === true) { | ||
| return Object.freeze({ offsetX: 1, offsetY: 1 }); | ||
| } | ||
| if (typeof shadow !== "object") { | ||
| return null; | ||
| } | ||
|
|
||
| const config = shadow as { offsetX?: unknown; offsetY?: unknown }; | ||
| const offsetX = readShadowOffset(config.offsetX, 1); | ||
| const offsetY = readShadowOffset(config.offsetY, 1); | ||
| if (offsetX <= 0 && offsetY <= 0) { | ||
| return null; | ||
| } | ||
| return Object.freeze({ offsetX, offsetY }); | ||
| } | ||
|
|
||
| export function getRuntimeNodeDamageRect(node: RuntimeInstance, rect: Rect): Rect { | ||
| if (node.vnode.kind !== "box") return rect; | ||
| const offsets = resolveShadowOffsets((node.vnode.props as BoxShadowProps).shadow); | ||
| if (!offsets) return rect; | ||
| return getRectWithShadow(rect, offsets); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
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.
appendDamageRectForInstanceIdnow pulls from_pooledDamageRectByInstanceId, but that map is only rebuilt during the layout-index pass (buildLayoutRectIndexes), so commits that skip layout can use stale shadow-aware bounds. Becauseshadowchanges are not layout-driving, toggling a box shadow on (or increasing offsets) in a commit withlayout: falsecan produce an undersized damage region, so incremental redraw clips away part of the newly visible shadow until a later full/layout render.Useful? React with 👍 / 👎.