Skip to content

Refactoring related to ReactPy v2.0.0#294

Open
shawncrawley wants to merge 8 commits intoreactive-python:mainfrom
shawncrawley:refactor-for-reactpy2.0
Open

Refactoring related to ReactPy v2.0.0#294
shawncrawley wants to merge 8 commits intoreactive-python:mainfrom
shawncrawley:refactor-for-reactpy2.0

Conversation

@shawncrawley
Copy link

@shawncrawley shawncrawley commented Feb 12, 2026

Description

My attempt at refactoring to align with ReactPy v2.0.0. This depends upon the refactors that were also made to reactpy-router to align with ReactPy v2.0.0 (see PR for that here).

There are a few remaining fixes/updates that I haven't been able to figure out yet. These are the related tests that fail when I run them locally:

  • tests\test_app\tests/test_components.py:230 ComponentTests.test_component_use_user_data
  • tests\test_app\tests/test_components.py:286 ComponentTests.test_component_use_user_data_with_default
  • tests\test_app\tests/test_components.py:685 ComponentTests.test_form_basic
  • tests\test_app\tests/test_components.py:779 ComponentTests.test_form_bootstrap
  • tests\test_app\tests/test_components.py:817 ComponentTests.test_form_orm_model
  • tests\test_app\tests/test_components.py:575 ComponentTests.test_pyscript_1_multifile

The first two are related to open discussion here. As for the rest, I still have no idea what the problem is after digging for hours.

Checklist

Please update this checklist as you complete each item:

  • Tests have been developed for bug fixes or new functionality.
  • The changelog has been updated, if necessary.
  • Documentation has been updated, if necessary.
  • GitHub Issues closed by this PR have been linked.

By submitting this pull request I agree that all contributions comply with this project's open source license(s).

@shawncrawley shawncrawley requested a review from a team as a code owner February 12, 2026 18:32
@shawncrawley
Copy link
Author

shawncrawley commented Feb 15, 2026

So I actually realized that most of the pyscript code here in reactpy-django is now duplicated in reactpy core. I went through and essentially removed essentially all of the duplicate code and just reference it in reactpy. With this change, I still get the same test failing that I couldn't ever figure out why before, but now I'm actually getting a py-script error rather than silent/masked failures. Here is that error:

Unhandled exception in event loop
Traceback (most recent call last):
  File "/lib/python3.13/site-packages/reactpy/executors/pyscript/layout_handler.py", line 157, in run
    update = await root_layout.render()
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/lib/python3.13/site-packages/reactpy/core/layout.py", line 122, in render
    return await self._parallel_render()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/lib/python3.13/site-packages/reactpy/core/layout.py", line 158, in _parallel_render
    return update_task.result()
           ~~~~~~~~~~~~~~~~~~^^
  File "/lib/python3.13/site-packages/reactpy/core/layout.py", line 174, in _create_layout_update
    new_state = await self._render_component(
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<6 lines>...
    )
    ^
  File "/lib/python3.13/site-packages/reactpy/core/layout.py", line 279, in _render_component
    await life_cycle_hook.affect_component_did_render()
  File "/lib/python3.13/site-packages/reactpy/core/_life_cycle_hook.py", line 232, in affect_component_did_render
    self.unset_current()
    ~~~~~~~~~~~~~~~~~~^^
  File "/lib/python3.13/site-packages/reactpy/core/_life_cycle_hook.py", line 271, in unset_current
    if HOOK_STACK.get().pop() is not self:
       ~~~~~~~~~~~~~~~~~~~~^^
IndexError: pop from empty list

I haven't pushed these code updates since I haven't solved this bug and wanted some feedback on it. Also, I wanted to make sure that purging most of the pyscript code from reactpy-django and instead referencing it in reactpy core is desired. Let me know your thoughts on this. I'm happy to push my code updates if desired.

…ot figure out why re-exported `reactpy/client` hook stack was broken on function based components)
@Archmonger
Copy link
Contributor

A lot of the PyScript logic in this repo has Django specific optimizations, so unfortunately nearly all of that code will remain duplicated for now.

Will make a follow-up issue to de-duplicate (make the variant in core to be more 'pluggable').

@shawncrawley
Copy link
Author

Gotcha. I really tried to compare the code in reactpy-django vs reactpy core to ensure I wasn't missing any django-specific stuff and only replace it if they were identical in their outcome, and it really seemed like a good chunk of it met that criteria. I of course trust you, I'm just surprised at what I must have missed. I'll stand down and let you round out the rest of this PR, since you've been at work on it. Thanks for your help!

@Archmonger
Copy link
Contributor

Feel free to switch to any pyscript code that doesn't break any Django specific logic. I think a decent amount of it relies on Django cache, template tags, and url routing though.

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