Skip to content

Fix auto_scroll end-following past code blocks / nested scrollables#6642

Merged
FeodorFitsner merged 2 commits into
flet-0.86from
auto-scroll-nested-and-jump-fix
Jul 5, 2026
Merged

Fix auto_scroll end-following past code blocks / nested scrollables#6642
FeodorFitsner merged 2 commits into
flet-0.86from
auto-scroll-nested-and-jump-fix

Conversation

@FeodorFitsner

@FeodorFitsner FeodorFitsner commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Follow-up to the auto_scroll end-following behavior: it stopped following once a tall child was inserted — most visibly a Markdown code block (streamed text scrolled fine, code blocks did not).

Two root causes in ScrollableControl:

  1. Nested scrollables. A Markdown code block renders inside its own horizontally-scrollable widget. The ScrollMetricsNotification listener reacted to those nested notifications too, tracking the wrong (horizontal) extent. Now it ignores nested scrollables (notification.depth != 0), per the standard Flutter guidance.

  2. Extent-jump unpin. _onScroll recomputed the pinned state purely from proximity (pixels >= maxScrollExtent - threshold). Inserting a tall child jumps maxScrollExtent past that threshold in a single frame while pixels stays put, so it flipped to unpinned and stopped following. Streamed text grows in sub-threshold steps so it never tripped. Now it only unpins when the user scrolls up (pixels decrease) and re-pins when the position returns to the end; content growing beneath a stationary position keeps it pinned.

flutter analyze on the changed control: no issues.

Companion to #6637 (the original follow-content-growth change).

Summary by Sourcery

Ensure scrollable auto-follow behavior remains pinned to the end when content grows, while ignoring nested scrollable metrics.

Bug Fixes:

  • Prevent auto-scroll from stopping when tall content such as Markdown code blocks is appended at the end of a scrollable.
  • Avoid incorrect end-following behavior caused by reacting to nested scrollables’ ScrollMetrics notifications instead of the main scrollable.
  • Fix unintended unpinning after large maxScrollExtent jumps by only changing pin state in response to user upward scrolling.

Two issues broke auto_scroll's end-following when a tall child (e.g. a Markdown
code block) was inserted:

- The ScrollMetricsNotification listener reacted to *nested* scrollables (a code
  block renders inside a horizontal scroller), tracking the wrong extent. Only
  react to this scrollable's own metrics (notification.depth == 0).
- _onScroll unpinned purely on proximity (pixels >= max - threshold). A tall
  insert jumps maxScrollExtent past the threshold in one frame while pixels
  stays put, flipping to unpinned so it stopped following. Now it only unpins
  when the user scrolls *up* (pixels decrease) and re-pins at the end; content
  growing beneath a stationary position keeps it pinned.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've reviewed this pull request using the Sourcery rules engine

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying flet-website-v2 with  Cloudflare Pages  Cloudflare Pages

Latest commit: ec0e821
Status: ✅  Deploy successful!
Preview URL: https://61c49988.flet-website-v2.pages.dev
Branch Preview URL: https://auto-scroll-nested-and-jump.flet-website-v2.pages.dev

View logs

The Pyodide↔Dart postMessage transport frames every packet as [type:u8][payload]
(0x00 = MsgPack Flet protocol frame, 0x01 = raw DataChannel frame), and
PyodideConnection.send_message prepends the 0x00 byte. The python_output shim,
however, posted the raw msgpack [7, {...}] with no type byte, so the Dart side
read msgpack's leading 0x92 (array-of-2 marker) as an unknown packet type and
silently dropped every stdout/stderr line — the host page's Console pane never
saw embedded-app output. Prepend the 0x00 type byte in both worker templates
(client + cookiecutter build template).
@FeodorFitsner FeodorFitsner merged commit f259b95 into flet-0.86 Jul 5, 2026
121 of 185 checks passed
@FeodorFitsner FeodorFitsner deleted the auto-scroll-nested-and-jump-fix branch July 5, 2026 21:41
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.

1 participant