Skip to content

Let handlers set properties, and report ones that can't run - #677

Merged
simonhamp merged 1 commit into
mainfrom
fix/handler-expressions
Nov 14, 2026
Merged

simonhamp merged 1 commit into
mainfrom
fix/handler-expressions

Conversation

@simonhamp

Copy link
Copy Markdown
Member

The Bottom Sheet and Modal docs show handlers like @press="$showSheet = true" and @dismiss="$showSheet = false". They never worked. The callback parser read the whole expression as a method name, no method had that name, and dispatchUiEvent() returned without a word. A sheet swiped away kept its visible property true, so every later tap that set it to true changed nothing and the sheet never opened again.

What changes

Handlers can now set a property:

<native:button label="Open" @press="$showSheet = true" />
<native:bottom-sheet :visible="$showSheet" @dismiss="$showSheet = false">
<native:pressable @press="$expanded = !$expanded">
<native:pressable @press="$tab = 'settings'">

The value must be a literal: true, false, null, a number or a quoted string. $prop = !$prop flips a bool. Nothing is evaluated. The parser turns these into two internal callbacks, __assignProperty and __toggleProperty, which set the property through ComponentState::set(), so #[Locked] is still refused and updating/updated hooks run. The same works in a child component's tag binding, like @saved="$open = false".

A handler that can't run is now reported instead of dropped. That covers a method the component doesn't have, an expression outside the syntax above ($a = foo(), $a = !$b), a property that isn't public, and a toggle on something that isn't a bool. With app.debug on it throws InvalidHandlerException, so the error screen names it. Without debug it's logged and nothing runs.

What to watch for

  • Apps that had a broken handler sitting quietly in a view will now see an error screen while debugging. That's the point, but it may surface old mistakes.
  • The child-tag binding path that used emit() used to skip a missing method silently. It reports it now too.
  • Fragment taps from Asgard servers use their own parser and are not affected.

Testing

New unit tests cover the parser, including expressions it must refuse. New feature tests cover a press, a sheet dismiss followed by reopening, toggles, strings, numbers and null, #[Locked], the updated hook, a child tag binding, and each kind of broken handler with debug on and off. The full suite passes with the usual "turns a component dd() into a readable failure" test filtered out, as it stops the run on main too. Pint is clean.

Found while building a demo screen where a swiped-away sheet would not reopen.

🤖 Generated with Claude Code

The docs show `@press="$showSheet = true"` and `@dismiss="$showSheet = false"`,
but the parser read those as method names and dispatch dropped them without a
word. A swiped-away sheet kept visible = true and never opened again.

A handler can now be `$prop = <literal>` (true, false, null, a number or a
quoted string) or `$prop = !$prop`. Nothing is evaluated. Both go through
ComponentState::set(), so #[Locked] and updated hooks apply, and they work in
child tag bindings too.

A handler that can't run (no such method, an unsupported expression, a
property that isn't public, a toggle on a non-bool) now throws
InvalidHandlerException under app.debug and is logged otherwise.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@simonhamp
simonhamp merged commit efcad02 into main Nov 14, 2026
6 checks passed
@simonhamp
simonhamp deleted the fix/handler-expressions branch November 14, 2026 16:39
simonhamp added a commit that referenced this pull request Nov 14, 2026
Brings in the handler expression fix (#677). Child event bindings now
run through runAction() with ActionSource::ParentBinding, so property
handlers and the action pipeline both apply.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gwleuverink added a commit that referenced this pull request Nov 17, 2026
Covers mobile PRs #452, #652, #653, #654, #655, #656, #658, #659, #661, #662, #663, #664, #666, #667, #668, #670, #671, #672, #673, #675, #677 and #678, and the commit on main without a PR: e9e2049 (Bifrost build service in the README). Main 1ad5cf5..5bcd753, 23 commits.

Ported to core on branch sync/mobile-main-2026-11-16 of NativePHP/core, which this merge needs: #658 "Sign the durable native-callback cache copy with the app key" (src/Support/NativeCallbacks.php), #667 (min-scale on Text), #661 (dragEnd handlers through invokeUiInteraction()), #670 (Element::closesOnNavigation() and its registry lookup, read by core's farewell frame), #675 (#[Memo] child components, captureRoots(), the compiled view checks once per frame, and the view creator in CoreServiceProvider), #452 (Transition::SlideToBottom and the transition argument on navigate(), back() and replace()) and #677 (property handlers and InvalidHandlerException). Memo and InvalidHandlerException move to core. Their old names resolve to core's through the alias shim.

Kept on this branch, as main has them: #670's BottomSheet::closesOnNavigation(), #452's transition on TopBarAction, #678's NativeLayout default, and the docblock #670 gave the farewell frame, which now sits on typesClosedInFarewellFrame(). #653 "Authenticate device events posted to /_native/api/events" merged with DispatchEventFromAppController holding both its check and the core marker check from 23300cc. Its new src/Support/NativeEventSignature.php stays in mobile, next to that controller.

Removed again in the merge: CallbackRegistry, Element, ElementRegistry, Text, NativeElementCollector, NativeTagPrecompiler, Transition and NativeCallbacks (main changed them, core has them), Memo and InvalidHandlerException (main added them, core has them), and both cacert.pem copies (main changed them, core ships the bundle). #659 is not ported, as core #21 brings the same file. Main's one line in NativeServiceProvider's view creator is in core's CoreServiceProvider now.

AGENTS.md keeps this branch's shared copy. The AGENTS.md that #658 added to main is not taken in. Where its text goes waits for the owner.

Adapted for the extraction: MemoComponentsTest reads nativeMemoRoots through core's NativeComponent, which declares it private.

Needs NativePHP/core branch sync/mobile-main-2026-11-16 (on #20, which is on #18), and #19 as before.

Tests, all on PHP 8.4.27, with core at a local merge of sync/mobile-main-2026-11-16 and #19 (323952d): mobile on this merge, 2,571 passed, 4 risky, 4 skipped (2,485 before the merge). PHPStan: the same 3 errors in RunsAndroid as before. Mobile main (5bcd753), 2,507 passed, 4 risky, 4 skipped. Desktop test:php, main (a9986fd) 2,253 passed and refactor/desktop-layout (87a60ce) 2,552 passed, the same as against the core of 2026-11-04.
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.

1 participant