fix(transform): #764 — module-init State() no longer breaks stateOnChange (v0.5.910)#766
Open
proggeramlug wants to merge 1 commit into
Open
fix(transform): #764 — module-init State() no longer breaks stateOnChange (v0.5.910)#766proggeramlug wants to merge 1 commit into
proggeramlug wants to merge 1 commit into
Conversation
…Change (v0.5.910) Gate `state_desugar` so it only rewrites a `State(...)` / `state(...)` binding to the synthetic `__state_*` keyed runtime when *no* handle-based state API (stateOnChange / stateBindTextfield / stateBindToggle / stateBindSlider / stateBindVisibility / stateBindTextNumeric) consumes that binding anywhere in the module — including function bodies and class methods, which is where the #763 reactive-Text desugar emits its `stateOnChange(cell, ...)` calls. Pre-fix, `const cell = State(""); stateOnChange(cell, cb); cell.set("v")` at module-init level updated `cell.value` correctly but never fired `cb` because the desugar replaced `cell`'s init with `Undefined` while leaving `stateOnChange(cell, ...)` untouched — handle-based FFI saw garbage and the subscriber registry stayed empty. NavStack / ForEach / `.set` / `.value` / `.get` / `.text` rewrites are unchanged (they have full keyed-side implementations); lowercase `state(...)` flows through #535 exactly as before when used purely keyed-API. Includes 4 unit tests in state_desugar.rs covering the gate (uppercase + stateOnChange skipped, lowercase + stateBindTextfield skipped, pure keyed-API still rewritten, handle use inside function body still gates module-init binding) and two integration fixtures under `test-files/`: - `test_issue_763_reactive_textfield.ts` — user's original UI repro (validated via AppleScript: typing and button click both update the standalone reactive Text widget). - `test_issue_764_state_at_module_init.ts` — CLI parity (stateOnChange callback fires correctly when State is at module-init). Both new TS fixtures need `--target macos` to link perry-ui-macos, so they join `test_issue_640_navstack_textfield` in the compile-smoke SKIP_TESTS list. NavStack regression check: #640 still routes A↔B. `cargo test --release -p perry-transform` 23/0/0; full workspace tests green. Refs #763.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
const cell = State("")at module-init level was hijacked byperry-transform'sstate_desugarpass — rewritten into the synthetic keyed runtime (__state_init+__state_set+__state_get) — whilestateOnChange(cell, ...)/stateBindTextfield(cell, ...)/ etc. were left untouched. The handle-based FFI sawundefinedas its widget handle, the subscriber registry stayed empty, and the callback never fired. Same path was breaking the v0.5.112 reactive-Text(\…${state.value}…`)IIFE desugar wheneverState()` appears at module-init..set/.value/.get/.textrewrites (and lowercasestate(...)flows from perry/ui: state→UI binding propagation only fires on --target harmonyos (deferred to v6.5) #535) are unchanged.state_desugarunit tests + 2 new integration fixtures undertest-files/. Workspace tests green; perry/ui: TextField in non-initially-active NavStack route doesn't accept geisterhand /type after screen.set #640 NavStack regression check still passes.Test plan
cargo test --release -p perry-transform— 23/0/0, includes the 4 new gate tests.test_issue_763_reactive_textfield.ts— AppleScript validation on macOS: typing into the TextField AND clicking the "set hello world" button both reactively update the standaloneText(\current state for text: ${text.value}`)` widget.test_issue_764_state_at_module_init.ts— CLI smoke:stateOnChangecallback fires on everycell.set(...).test_issue_640_navstack_textfield.tsstill routes A↔B correctly.Notes
--target macosto link perry-ui-macos, so they jointest_issue_640_navstack_textfieldin the compile-smokeSKIP_TESTSlist.Text(\…${state.value}…`)toperry_ui_state_bind_text_template" feature request, but investigation showed the IIFE-based auto-bind has shipped since v0.5.112 — the user-visible failure in #763 is actually this separate module-init regression. The runtime-sideperry_ui_state_bind_text_template` consolidation is left as a future architectural improvement.