Skip to content

Commit bfb0d5c

Browse files
committed
test serial renders too
1 parent 80d3b7a commit bfb0d5c

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/py/reactpy/reactpy/_option.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ def current(self) -> _O:
6868
def current(self, new: _O) -> None:
6969
self.set_current(new)
7070

71+
@current.deleter
72+
def current(self) -> None:
73+
self.unset()
74+
7175
def subscribe(self, handler: Callable[[_O], None]) -> Callable[[_O], None]:
7276
"""Register a callback that will be triggered when this option changes"""
7377
if not self.mutable:
@@ -123,7 +127,8 @@ def unset(self) -> None:
123127
msg = f"{self} cannot be modified after initial load"
124128
raise TypeError(msg)
125129
old = self.current
126-
delattr(self, "_current")
130+
if hasattr(self, "_current"):
131+
delattr(self, "_current")
127132
if self.current != old:
128133
for sub_func in self._subscribers:
129134
sub_func(self.current)

src/py/reactpy/tests/test_core/test_layout.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
import gc
33
import random
44
import re
5+
from unittest.mock import patch
56
from weakref import finalize
67
from weakref import ref as weakref
78

89
import pytest
910

1011
import reactpy
1112
from reactpy import html
12-
from reactpy.config import REACTPY_DEBUG_MODE
13+
from reactpy.config import REACTPY_DEBUG_MODE, REACTPY_FEATURE_CONCURRENT_RENDERING
1314
from reactpy.core.component import component
1415
from reactpy.core.hooks import use_effect, use_state
1516
from reactpy.core.layout import Layout
@@ -20,6 +21,7 @@
2021
assert_reactpy_did_log,
2122
capture_reactpy_logs,
2223
)
24+
from reactpy.testing.common import poll
2325
from reactpy.utils import Ref
2426
from tests.tooling import select
2527
from tests.tooling.aio import Event
@@ -29,6 +31,12 @@
2931
from tests.tooling.select import element_exists, find_element
3032

3133

34+
@pytest.fixture(autouse=True, params=[True, False])
35+
def concurrent_rendering(request):
36+
with patch.object(REACTPY_FEATURE_CONCURRENT_RENDERING, "current", request.param):
37+
yield request.param
38+
39+
3240
@pytest.fixture(autouse=True)
3341
def no_logged_errors():
3442
with capture_reactpy_logs() as logs:
@@ -832,17 +840,19 @@ def some_effect():
832840
async with reactpy.Layout(Root()) as layout:
833841
await layout.render()
834842

835-
assert effects == ["mount x"]
843+
await poll(lambda: effects).until_equals(["mount x"])
836844

837845
set_toggle.current()
838846
await layout.render()
839847

840-
assert effects == ["mount x", "unmount x", "mount y"]
848+
await poll(lambda: effects).until_equals(["mount x", "unmount x", "mount y"])
841849

842850
set_toggle.current()
843851
await layout.render()
844852

845-
assert effects == ["mount x", "unmount x", "mount y", "unmount y", "mount x"]
853+
await poll(lambda: effects).until_equals(
854+
["mount x", "unmount x", "mount y", "unmount y", "mount x"]
855+
)
846856

847857

848858
async def test_layout_does_not_copy_element_children_by_key():
@@ -1253,7 +1263,10 @@ def App():
12531263
assert c["attributes"]["color"] == "blue"
12541264

12551265

1256-
async def test_concurrent_renders():
1266+
async def test_concurrent_renders(concurrent_rendering):
1267+
if not concurrent_rendering:
1268+
raise pytest.skip("Concurrent rendering not enabled")
1269+
12571270
child_1_hook = HookCatcher()
12581271
child_2_hook = HookCatcher()
12591272
child_1_rendered = Event()

0 commit comments

Comments
 (0)