Skip to content

use_async_effect cleanup not executed when dependencies change #1327

Closed

Description

@Archmonger

Discussed in #1326

Originally posted by masipcat January 24, 2026
Hello,

First of all, thank you for this project. I’ve been using ReactPy 2.0 in a couple of small pet projects, and it’s been really nice to work with so far.

As I mentioned in the title, the cleanup function is not executed when the dependency of the use_async_effect changes. The issue can be reproduced by transforming the test_memoized_effect_cleanup_only_triggered_before_new_effect to use an async effect:

diff --git a/tests/test_core/test_hooks.py b/tests/test_core/test_hooks.py
index 93e64a69..434d7ad3 100644
--- a/tests/test_core/test_hooks.py
+++ b/tests/test_core/test_hooks.py
@@ -451,8 +451,8 @@ async def test_memoized_effect_cleanup_only_triggered_before_new_effect():
     def ComponentWithEffect():
         state, set_state_callback.current = reactpy.hooks.use_state(first_value)
 
-        @reactpy.hooks.use_effect(dependencies=[state])
-        def effect():
+        @reactpy.hooks.use_async_effect(dependencies=[state])
+        async def effect():
             def cleanup():
                 cleanup_trigger_count.current += 1
 

Thank you in advance

Activity

  1. added a commit that references this issue on Jan 24, 2026
    da1ef0a
  2. changed the title [-]`use_async_effect` cleanup functions not executed in 2.0.0b7[/-] [+]`use_async_effect` cleanup not executed when dependencies change[/+] on Jan 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions