mirror of
https://github.com/rio-labs/rio.git
synced 2026-05-03 09:30:06 -05:00
misc fixes
This commit is contained in:
@@ -964,6 +964,7 @@ Sitemap: {base_url / "rio/sitemap.xml"}
|
||||
try:
|
||||
sess = self._active_session_tokens[session_token]
|
||||
except KeyError:
|
||||
revel.debug("Response: Invalid token")
|
||||
# Inform the client that this session token is invalid
|
||||
await websocket.close(
|
||||
3000, # Custom error code
|
||||
@@ -975,7 +976,16 @@ Sitemap: {base_url / "rio/sitemap.xml"}
|
||||
# connection. Browsers have a "duplicate tab" feature that can
|
||||
# create a 2nd tab with the same session token as the original one,
|
||||
# and in that case we want to create a new session.
|
||||
if not sess._rio_transport.is_closed:
|
||||
#
|
||||
# Sometimes the client actually reacts faster than we do, so we'll
|
||||
# wait a little while before checking if the session is still
|
||||
# connected.
|
||||
try:
|
||||
await asyncio.wait_for(
|
||||
sess._rio_transport.closed_event.wait(), 2
|
||||
)
|
||||
except asyncio.TimeoutError:
|
||||
revel.debug("Response: Valid token, but session is still open")
|
||||
await websocket.close(
|
||||
3000, # Custom error code
|
||||
"Invalid session token.",
|
||||
|
||||
@@ -95,9 +95,9 @@ class Grid(FundamentalComponent):
|
||||
|
||||
# Hide internal attributes from the type checker
|
||||
if not t.TYPE_CHECKING:
|
||||
# These must be annotated, otherwise rio won't understand that grids have
|
||||
# child components and won't copy over the new values when two Grids are
|
||||
# reconciled.
|
||||
# These must be annotated, otherwise rio won't understand that grids
|
||||
# have child components and won't copy over the new values when two
|
||||
# Grids are reconciled.
|
||||
_children: list[rio.Component]
|
||||
_child_positions: list[GridChildPosition]
|
||||
|
||||
|
||||
@@ -422,6 +422,7 @@ class Session(unicall.Unicall):
|
||||
try:
|
||||
return await self._rio_transport.receive()
|
||||
except TransportInterrupted:
|
||||
revel.debug(f"Session {self} transport interrupted")
|
||||
self._is_connected_event.clear()
|
||||
self._app_server._disconnected_sessions[self] = time.monotonic()
|
||||
|
||||
|
||||
@@ -32,13 +32,15 @@ class FastapiWebsocketTransport(abstract_transport.AbstractTransport):
|
||||
revel.debug(f"Websocket closed: {err.code} {err!r}")
|
||||
self._closed_intentionally = err.code == 1001
|
||||
|
||||
self.closed_event.set()
|
||||
|
||||
revel.debug(
|
||||
f"Websocket closed intentionally? {self._closed_intentionally}"
|
||||
)
|
||||
if self._closed_intentionally:
|
||||
raise abstract_transport.TransportClosedIntentionally
|
||||
raise abstract_transport.TransportClosedIntentionally()
|
||||
else:
|
||||
raise abstract_transport.TransportInterrupted
|
||||
raise abstract_transport.TransportInterrupted()
|
||||
|
||||
async def close(self) -> None:
|
||||
self._closed_intentionally = True
|
||||
|
||||
@@ -179,6 +179,11 @@ async def test_populate_dead_child():
|
||||
await asyncio.sleep(1.5)
|
||||
|
||||
# Make sure the dead component wasn't sent to the frontend
|
||||
assert not test_client._outgoing_messages, (
|
||||
#
|
||||
# Note: Even though we cleared the outgoing messages, it's possible that
|
||||
# some `registerFont` messages were sent afterwards. So unfortunately we
|
||||
# can't assert that no message was sent at all, but we can assert that
|
||||
# no components were updated.
|
||||
assert not test_client._last_updated_components, (
|
||||
"Unmounted component was sent to the frontend"
|
||||
)
|
||||
|
||||
@@ -205,6 +205,7 @@ async def test_binding_doesnt_update_children() -> None:
|
||||
)
|
||||
|
||||
async with rio.testing.TestClient(ComponentWithBinding) as test_client:
|
||||
root_component = test_client.get_component(ComponentWithBinding)
|
||||
text_input = test_client.get_component(rio.TextInput)
|
||||
text = test_client.get_component(rio.Text)
|
||||
|
||||
@@ -213,4 +214,4 @@ async def test_binding_doesnt_update_children() -> None:
|
||||
await text_input._on_message_({"type": "confirm", "text": "hello"})
|
||||
|
||||
# Only the Text component has changed in this rebuild
|
||||
assert test_client._last_updated_components == {text}
|
||||
assert test_client._last_updated_components == {root_component, text}
|
||||
|
||||
Reference in New Issue
Block a user