Skip to content

fix(usvgr): hash a nested group's opacity and blend mode in the layer cache key - #25

Merged
dmtrKovalenko merged 1 commit into
mainfrom
fix/nested-group-opacity-cache-key
Nov 14, 2026
Merged

dmtrKovalenko merged 1 commit into
mainfrom
fix/nested-group-opacity-cache-key

Conversation

@dmtrKovalenko

@dmtrKovalenko dmtrKovalenko commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Fixes dmtrKovalenko/fframes#264.

Problem

render_isolated_group caches the layer of an isolated group under the group's Hash, the layer size and the final transform. impl Hash for Group left out opacity and blend_mode, because the renderer applies them when it draws the cached layer. But the impl hashed the children with the same Hash, so it left them out for nested groups too, and those are part of the cached pixels.

Two frames that differ only in the opacity or blend mode of a nested group got the same key. The second frame reused the layer of the first, so a fade inside a group with opacity, a clip, a mask or a filter did not fade when the frames shared a cache.

Fix

Group::hash still leaves out the opacity and blend mode of the group it is called on. For every group below it, it hashes them. Group::content_hash already does the same for the filter layer cache.

A group's own layer keeps its key when only its own opacity changes, so that case still hits the cache.

Test

nested_group_opacity_and_blend_mode_change_cached_layer renders three frames with one SvgrCache and compares each with a render without a cache. The frames differ in the nested group's opacity, then in its blend mode. It fails on main with stale layer for opacity="0.25".

cargo test -p svgr -p usvgr passes.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected rendering for SVGs with nested groups that use opacity or blend modes. These visual effects now remain consistent whether the result is rendered from cache or generated fresh, preventing differences in appearance between the two paths.

… cache key

The layer of an isolated group is cached by the group's Hash, which left out
opacity and blend mode for the group and for every group inside it. Those of a
nested group are part of the cached pixels, so a frame that changed only them
reused the layer of an earlier frame.
@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Group hashing now includes opacity and blend mode for nested groups. A regression test compares cached and uncached rendering for SVGs with differing nested group opacity and blend mode.

Changes: Nested Group Cache Hashing

Layer / File(s) Summary
Nested group hashing and regression test
crates/usvgr/src/tree/mod.rs, crates/svgr/src/render.rs
Group hashing includes opacity and blend mode for nested groups and recursively hashes child groups. The regression test compares cached and uncached pixel data across three SVG variants.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: razrfalcon, its-just-nans

Merge Risk: Minimal · up to 041d2

This change fixes stale cached layers when a nested group's opacity or blend mode changes across frames, while preserving cache hits for the isolated group's own opacity. It adds a regression test for the case. No merge-blocking risk was identified.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the specific change: Group hashing in usvgr now includes a nested group's opacity and blend mode in the layer cache key. The raw summary and PR objectives confirm the Group::hash chang…
Description check Passed The description follows the repository's rules. It is not a dependency update, formatting fix, clippy fix, or compiler warning fix. It describes a meaningful bug fix: stale cached layers for nested gr…
Linked Issues check Passed Directly linked issue #264 requires that a nested group's opacity and blend mode enter the layer cache key, while the isolated group's own opacity stays out of its key. The PR summary states that `Gro…
Out of Scope Changes check Passed The PR changes two files according to the summary: the Group hash implementation in usvgr src/tree/mod.rs (+26/-4) and a new regression test in svgr src/render.rs (+53/-0). The hash change is th…
Full details: Title check

Explanation

The title names the specific change: Group hashing in usvgr now includes a nested group's opacity and blend mode in the layer cache key. The raw summary and PR objectives confirm the Group::hash change, and the title matches that change. The title uses the conventional fix(usvgr) prefix and is 79 characters long.

Full details: Description check

Explanation

The description follows the repository's rules. It is not a dependency update, formatting fix, clippy fix, or compiler warning fix. It describes a meaningful bug fix: stale cached layers for nested groups whose opacity or blend mode changes. It states the problem, the fix, and a regression test, and it links issue #264. Its cause and fix sections match the raw summary. The template has no required headings, so the description meets it.

Full details: Linked Issues check

Explanation

Directly linked issue #264 requires that a nested group's opacity and blend mode enter the layer cache key, while the isolated group's own opacity stays out of its key. The PR summary states that Group::hash in usvgr src/tree/mod.rs now omits the hashed group's own opacity and blend mode, and includes both for nested child groups, recursively. This matches the fix requested in #264 and the Group::content_hash precedent cited there. The PR also adds nested_group_opacity_and_blend_mode_change_cached_layer in svgr src/render.rs, which renders three frames with one SvgrCache and compares each with an uncached render. That test covers the nested opacity and blend mode cases from #264. The author reports that it fails on main and that cargo test -p svgr -p usvgr passes. Limitation: the repository read of crates/usvgr/src/tree/mod.rs at head was truncated before the Group hash body, so the code change is confirmed from the PR summary and description, not from the blob itself. The test was not run during this assessment.

Full details: Out of Scope Changes check

Explanation

The PR changes two files according to the summary: the Group hash implementation in usvgr src/tree/mod.rs (+26/-4) and a new regression test in svgr src/render.rs (+53/-0). The hash change is the fix that #264 requests. The test directly exercises the reported stale-layer behavior. Both changes connect to the linked issue, and the summary reports no public API declaration changes. No unrelated change was identified. Limitation: the truncated usvgr blob read did not allow line-level confirmation of the hash body.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4adfcbf8-1ec3-4e54-9b12-3a0f5aca59bc
Commits

Reviewing files that changed from the base of the PR and between 4804366 and 041d244.

Files selected for processing: 2

  • crates/svgr/src/render.rs
  • crates/usvgr/src/tree/mod.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@dmtrKovalenko
dmtrKovalenko merged commit c2ffaba into main Nov 14, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A nested group's opacity is left out of the layer cache key, so its fade renders stale

1 participant