Skip to content

fix(python): retain returned effect cleanups - #6983

Open
mangod12 wants to merge 1 commit into
flet-dev:mainfrom
mangod12:fix/use-effect-returned-cleanup
Open

mangod12 wants to merge 1 commit into
flet-dev:mainfrom
mangod12:fix/use-effect-returned-cleanup

Conversation

@mangod12

@mangod12 mangod12 commented Oct 18, 2026 •

Copy link
Copy Markdown

Setup-returned cleanup callbacks are now kept separate from the explicit cleanup= callback, so rerenders do not erase them. Returned cleanup runs before a dependency-triggered setup and on unmount; unmount also queues cancellation of a pending async setup task.

Tests: 11 focused Python tests pass; Ruff check and format pass.

AI-assisted implementation; reviewed and tested. Fixes #6963.

Summary by Sourcery

Preserve returned effect cleanups throughout the effect lifecycle and cancel pending asynchronous setups during unmount.

Bug Fixes:

  • Preserve effect setup-returned cleanup callbacks across rerenders and execute them before dependency-triggered setup or on unmount.
  • Ensure unmount schedules cleanup when an effect setup task is still pending, allowing the task to be cancelled.

Enhancements:

  • Separate setup-returned cleanup callbacks from explicit cleanup callbacks and track effect lifecycle work consistently.

Tests:

  • Add focused tests covering cleanup retention, rerender and unmount behavior, and cancellation of pending asynchronous setups.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@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.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

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.

use_effect: a cleanup returned by a sync setup is lost when the component re-renders

2 participants