Skip to content

Commit cfe053f

Browse files
apiadclaude
andcommitted
fix(app): re-export _call_rpc and _call_realtime from violetear.client
Same root cause as the ReactiveRegistry import bug in 835dede: client.py now lives inside the violetear.client module (good — gives state.py and dom.py a proper module to import from). But the bundle's server-side stubs (generated by _generate_server_stubs, one per @app.server.rpc / .realtime function) reference `_call_rpc` and `_call_realtime` as bare names at bundle-module scope. Those names were globals when client.py was exec'd directly into the bundle; after the module-injection, they're attributes of violetear.client, not bundle globals. Symptom in browser: clicking precise mode (which triggers the precise_convert RPC stub) raised NameError: name '_call_rpc' is not defined Fix: add _call_rpc + _call_realtime to the re-export list in client_injection. New e2e test (test_03_interactive_precise_mode_rpc_roundtrip) catches this specific regression — it toggles to precise mode and waits for the feet field to reflect the high-precision constant. Different code path from the reactive-update test (which is client-only). 43 fast + 3 e2e all green. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 835dede commit cfe053f

2 files changed

Lines changed: 43 additions & 2 deletions

File tree

tests/test_examples_e2e.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,37 @@ def test_03_interactive_reactive_update_propagates(example_server, page):
114114
assert errors == [], "Browser errors during reactive update:\n " + "\n ".join(
115115
errors
116116
)
117+
118+
119+
@pytest.mark.e2e
120+
def test_03_interactive_precise_mode_rpc_roundtrip(example_server, page):
121+
"""Toggling to precise mode + typing routes the conversion through the
122+
server-side RPC stub (`_call_rpc` in the bundle). Catches regressions in
123+
the RPC-stub plumbing — different code path from the client-only proxy
124+
notify exercised by the reactive-update test above."""
125+
base = example_server("03_interactive.py")
126+
errors = _collect_browser_errors(page)
127+
128+
page.goto(base + "/")
129+
page.wait_for_function(
130+
"() => document.getElementById('violetear-cloak') === null",
131+
timeout=HYDRATION_TIMEOUT_MS,
132+
)
133+
134+
# Toggle precise mode via the radio. The on_mode_change callback calls
135+
# recompute_from_meters which calls precise_convert (the RPC stub).
136+
page.check('input[type="radio"][value="precise"]')
137+
138+
# Wait for feet to reflect the precise constant (3.28083989501 vs 3.281
139+
# in quick mode). After toggling at meters=1.0, feet should be ~3.28084.
140+
page.wait_for_function(
141+
"() => {"
142+
" const v = parseFloat(document.querySelector('input[data-bind-value=\"UiState.feet\"]').value);"
143+
" return v > 3.2808 && v < 3.2809;"
144+
"}",
145+
timeout=5_000,
146+
)
147+
148+
assert errors == [], "Browser errors during precise-mode RPC:\n " + "\n ".join(
149+
errors
150+
)

violetear/app.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -711,13 +711,20 @@ def _generate_bundle(self) -> str:
711711
exec({repr(runtime_code)}, m_client.__dict__)
712712
713713
import violetear.client
714-
# Re-export the names the bundle's init_code and user code call at
715-
# module scope (hydrate(globals()) and _register_client_event(...)).
714+
# Re-export the names the bundle calls at module scope:
715+
# - hydrate / _register_client_event: used by init_code
716+
# - _call_rpc / _call_realtime: used by the server-stub functions
717+
# generated by _generate_server_stubs (one stub per @app.server.rpc
718+
# or @app.server.realtime function)
719+
# - ReactiveRegistry: kept for symmetry / direct use
720+
# - _dispatch_client_event: kept for symmetry
716721
from violetear.client import (
717722
hydrate,
718723
ReactiveRegistry,
719724
_register_client_event,
720725
_dispatch_client_event,
726+
_call_rpc,
727+
_call_realtime,
721728
)
722729
"""
723730
)

0 commit comments

Comments
 (0)