Skip to content

fix(ui): Don't count anchor corrections in ScrollablePositionedList#2693

Merged
renefloor merged 2 commits into
masterfrom
fix/performLayout-loop-count
May 27, 2026
Merged

fix(ui): Don't count anchor corrections in ScrollablePositionedList#2693
renefloor merged 2 commits into
masterfrom
fix/performLayout-loop-count

Conversation

@renefloor
Copy link
Copy Markdown
Contributor

@renefloor renefloor commented May 27, 2026

Submit a pull request

CLA

  • I have signed the Stream CLA (required).
  • The code changes follow best practices
  • Code changes are tested (add some information if not applicable)

Description of the pull request

Screenshots / Videos

What was happening:

The performLayout loop has a budget of 10 cycles (_maxLayoutCycles = 10). Each non-converging iteration increments count. With our custom fitAnchor logic, the lifecycle during fast scrolling was:

  1. N cycles consumed by sliver corrections — when fast-scrolling loads new messages, SliverList children get laid out with new sizes and may request scrollOffsetCorrection to keep the viewport stable.
  2. +1 cycle consumed by the fitAnchor branch (count += 1 before continue) — our custom code that overrides the anchor when content fits in the viewport.
  3. +1 cycle consumed when applyContentDimensions returns false (pixel position clamped).
  4. = N+2 total. When N ≥ 8 (which can happen during a fast fling through many messages), that exceeds 10.
    The fix:

The fitAnchor pass is a deliberate one-time correction, not an oscillation. The upstream library's UnboundedRenderViewport doesn't have this pass at all — it was our addition to handle the edge case where a short list would appear centered instead of bottom-pinned. This pass must not consume a slot from the oscillation budget. Removing count += 1 gives back that cycle, meaning you now get the full 10 cycles for actual sliver oscillations before the assert fires.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed viewport layout behavior in scrollable positioned lists: one-time anchor adjustments no longer consume layout-cycle budget. This improves stability and smoothness during rapid scrolling, reducing the chance of layout cycle errors and ensuring more reliable re-layouts of message lists.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1e33606f-a507-478d-b39c-80ee5fd8b14e

📥 Commits

Reviewing files that changed from the base of the PR and between 114bfa9 and 20e6b78.

📒 Files selected for processing (1)
  • packages/stream_chat_flutter/CHANGELOG.md
✅ Files skipped from review due to trivial changes (1)
  • packages/stream_chat_flutter/CHANGELOG.md

📝 Walkthrough

Walkthrough

The viewport layout logic no longer consumes a layout-cycle slot when applying a one-time fit anchor correction that adjusts effectiveAnchor. This preserves the _maxLayoutCycles budget for subsequent sliver-correction attempts, preventing the anchor adjustment from interfering with re-layout iteration limits.

Changes

Fit Anchor Layout Cycle Budget

Layer / File(s) Summary
Fit anchor correction without budget consumption
packages/stream_chat_flutter/lib/scrollable_positioned_list/src/viewport.dart, packages/stream_chat_flutter/CHANGELOG.md
When applying the fit anchor adjustment to flush leading content to the axis-leading edge in UnboundedRenderViewport.performLayout, the layout-cycle counter is no longer incremented. A changelog entry describing the fix for a RenderViewport layout-cycle error was also added.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • VelikovPetar

Poem

🐰 A viewport hops without a care,
When anchors fit just right in there—
One budget slot? Now it's kept free!
Re-layout cycles dance with glee. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: preventing anchor corrections from being counted in the layout cycle budget for ScrollablePositionedList.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/performLayout-loop-count

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.38%. Comparing base (386807d) to head (20e6b78).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2693      +/-   ##
==========================================
- Coverage   65.38%   65.38%   -0.01%     
==========================================
  Files         423      423              
  Lines       26665    26664       -1     
==========================================
- Hits        17436    17434       -2     
- Misses       9229     9230       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@renefloor renefloor merged commit d85ff66 into master May 27, 2026
22 checks passed
@renefloor renefloor deleted the fix/performLayout-loop-count branch May 27, 2026 14:28
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.

2 participants