fix(hooks): forward all arguments in useAppEvent for custom events - #341
Conversation
🦋 Changeset detectedLatest commit: 8248d54 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
commit: |
There was a problem hiding this comment.
🟢 Approval recommended
The behavioral fix is correct and low-risk, and the added regression test covers the reported failure mode.
Pull request overview
Fixes useAppEvent so event callbacks receive all arguments for non-built-in/custom events (including events fired via app.fire(...)), instead of silently dropping them.
Changes:
- Simplified the internal
handlerinuseAppEventto forward(...args)directly to the provided callback. - Added a test that fires a custom event with multiple arguments and asserts the callback receives them.
- Added a changeset to publish the fix as a patch release.
File summaries
| File | Description |
|---|---|
| packages/lib/src/hooks/use-app-event.ts | Removes the update-only special casing and forwards all event arguments to the callback. |
| packages/lib/src/hooks/use-app-event.test.tsx | Adds a regression test ensuring custom event arguments are forwarded through useAppEvent. |
| .changeset/deep-towns-attend.md | Declares a patch release for the argument-forwarding fix. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
abstrakt8
left a comment
There was a problem hiding this comment.
Thanks, looks good! Making some changes and then merging it in
Assert the callback fired once before inspecting its arguments, compare only the leading args since PlayCanvas pads fire() to eight, and update the header note now that custom events can be fired in tests.
Summary
useAppEventonly forwarded the callback argument for the built-inupdateevent. For every other event (including custom events fired viaapp.fire(...)) the callback was invoked with no arguments at all.Root cause
Only
'update'was special-cased to receive its argument. Every other event was invoked with zero arguments.Fix
Forwards all arguments passed to
app.fire(...)generically.update,prerender, andpostrendercontinue to work exactly as before, since they simply receive their normal arguments through the same spread.Testing
Added a new test (
should forward all arguments to the callback for custom events) that fires a custom event viaapp.fire('levelComplete', 3, 1000)and asserts the callback receives both arguments.I verified this test fails against the old implementation (callback called with no arguments) and passes against the fix, confirming the test actually exercises the bug rather than passing coincidentally.
Note: the existing test file has a comment explaining that built-in input events can't be fired in the
nulldevice type used in tests. This doesn't apply here :app.fire(...)is the underlyingEventHandlermechanism, not a hardware input source, so it works fine in the test environment.