Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF-3203] Find a DOM event-like object in addEvents #3706

Merged
merged 2 commits into from
Jul 30, 2024

Conversation

masenf
Copy link
Collaborator

@masenf masenf commented Jul 25, 2024

Do NOT assume that the first or last arg is the browser event that triggered the event handler.

Instead, pass all of the args through and find the first object which defines preventDefault and treat that as the event.

This fixes stop_propagation and prevent_default on recharts charts, which define their mouse event handler signatures as (nextState, event). Before this fix, the generated code was passing nextState through as _e and since the event actions were not defined on that object, they had no effect.

This also fixes some other funny behavior where the arg_def was being passed through in parenthesis, which in JS evaluates to the last item in the list. So even if we defined some more complex args_spec for a particular trigger that correctly defined it's _e as the first argument, this would still be broken, because when multiple arguments were defined in an arg_spec, the last one was implicitly being treated as the browser event.

Do NOT assume that the first or last arg is the browser event that triggered
the event handler.

Instead, pass all of the `args` through and find the first object which defines
`preventDefault` and treat that as the event.

This fixes `stop_propagation` and `prevent_default` on recharts charts, which
define their mouse event handler signatures as `(nextState, event)`. Before
this fix, the generated code was passing `nextState` through as `_e` and since
the event actions were not defined on that object, they had no effect.

This also fixes some other funny behavior where the `arg_def` was being passed
through in parenthesis, which in JS evaluates to the last item in the list. So
even if we defined some more complex `args_spec` for a particular trigger that
correctly defined it's `_e` as the first argument, this would still be broken,
because when multiple arguments were defined in an `arg_spec`, the _last_ one
was implicitly being treated as the browser event.
Copy link
Contributor

@picklelo picklelo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@picklelo picklelo merged commit 06833f6 into main Jul 30, 2024
47 checks passed
cutoffthetop referenced this pull request in robert-koch-institut/mex-editor Aug 8, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [reflex](https://reflex.dev)
([source](https://togithub.com/reflex-dev/reflex)) |
project.dependencies | patch | `==0.5.8` -> `==0.5.9` |

---

### Release Notes

<details>
<summary>reflex-dev/reflex (reflex)</summary>

###
[`v0.5.9`](https://togithub.com/reflex-dev/reflex/releases/tag/v0.5.9)

[Compare
Source](https://togithub.com/reflex-dev/reflex/compare/v0.5.8...v0.5.9)

#### Bug Fixes

- fix silly bug when style is set directly to breakpoints by
[@&#8203;adhami3310](https://togithub.com/adhami3310) in
[https://github.com/reflex-dev/reflex/pull/3719](https://togithub.com/reflex-dev/reflex/pull/3719)
- Fix event actions like `stop_propagation` for recharts event triggers
- \[REF-3203] Find a DOM event-like object in addEvents by
[@&#8203;masenf](https://togithub.com/masenf) in
[https://github.com/reflex-dev/reflex/pull/3706](https://togithub.com/reflex-dev/reflex/pull/3706)
- fix initial_value for computed_var by
[@&#8203;benedikt-bartscher](https://togithub.com/benedikt-bartscher) in
[https://github.com/reflex-dev/reflex/pull/3726](https://togithub.com/reflex-dev/reflex/pull/3726)
- add test for initial state dict by
[@&#8203;benedikt-bartscher](https://togithub.com/benedikt-bartscher) in
[https://github.com/reflex-dev/reflex/pull/3727](https://togithub.com/reflex-dev/reflex/pull/3727)
- Improve Client-Side Routing on Page Not Found by
[@&#8203;Manas1820](https://togithub.com/Manas1820) in
[https://github.com/reflex-dev/reflex/pull/3723](https://togithub.com/reflex-dev/reflex/pull/3723)
- Use the new state name when setting `is_hydrated` to false by
[@&#8203;masenf](https://togithub.com/masenf) in
[https://github.com/reflex-dev/reflex/pull/3738](https://togithub.com/reflex-dev/reflex/pull/3738)
- Use `._is_mutable()` to account for parent state proxy by
[@&#8203;masenf](https://togithub.com/masenf) in
[https://github.com/reflex-dev/reflex/pull/3739](https://togithub.com/reflex-dev/reflex/pull/3739)

#### Doc Updates

- Add comments to html by [@&#8203;Alek99](https://togithub.com/Alek99)
in
[https://github.com/reflex-dev/reflex/pull/3731](https://togithub.com/reflex-dev/reflex/pull/3731)

#### Var Refactor

This release includes some new experimental features being developed
incrementally in reflex.\_x.vars.

- \[REF-3328] Implement **getitem** for ArrayVar by
[@&#8203;adhami3310](https://togithub.com/adhami3310) in
[https://github.com/reflex-dev/reflex/pull/3705](https://togithub.com/reflex-dev/reflex/pull/3705)
- add type hinting to existing types by
[@&#8203;adhami3310](https://togithub.com/adhami3310) in
[https://github.com/reflex-dev/reflex/pull/3729](https://togithub.com/reflex-dev/reflex/pull/3729)

**Full Changelog**:
reflex-dev/reflex@v0.5.8...v0.5.9

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://togithub.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC4xOC4xNyIsInVwZGF0ZWRJblZlciI6IjM4LjIzLjAiLCJ0YXJnZXRCcmFuY2giOiJtYWluIiwibGFiZWxzIjpbXX0=-->
cutoffthetop referenced this pull request in robert-koch-institut/mex-drop Aug 20, 2024
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [reflex](https://reflex.dev)
([source](https://togithub.com/reflex-dev/reflex)) |
project.dependencies | patch | `==0.5.8` -> `==0.5.9` |

---

### Release Notes

<details>
<summary>reflex-dev/reflex (reflex)</summary>

###
[`v0.5.9`](https://togithub.com/reflex-dev/reflex/releases/tag/v0.5.9)

[Compare
Source](https://togithub.com/reflex-dev/reflex/compare/v0.5.8...v0.5.9)

#### Bug Fixes

- fix silly bug when style is set directly to breakpoints by
[@&#8203;adhami3310](https://togithub.com/adhami3310) in
[https://github.com/reflex-dev/reflex/pull/3719](https://togithub.com/reflex-dev/reflex/pull/3719)
- Fix event actions like `stop_propagation` for recharts event triggers
- \[REF-3203] Find a DOM event-like object in addEvents by
[@&#8203;masenf](https://togithub.com/masenf) in
[https://github.com/reflex-dev/reflex/pull/3706](https://togithub.com/reflex-dev/reflex/pull/3706)
- fix initial_value for computed_var by
[@&#8203;benedikt-bartscher](https://togithub.com/benedikt-bartscher) in
[https://github.com/reflex-dev/reflex/pull/3726](https://togithub.com/reflex-dev/reflex/pull/3726)
- add test for initial state dict by
[@&#8203;benedikt-bartscher](https://togithub.com/benedikt-bartscher) in
[https://github.com/reflex-dev/reflex/pull/3727](https://togithub.com/reflex-dev/reflex/pull/3727)
- Improve Client-Side Routing on Page Not Found by
[@&#8203;Manas1820](https://togithub.com/Manas1820) in
[https://github.com/reflex-dev/reflex/pull/3723](https://togithub.com/reflex-dev/reflex/pull/3723)
- Use the new state name when setting `is_hydrated` to false by
[@&#8203;masenf](https://togithub.com/masenf) in
[https://github.com/reflex-dev/reflex/pull/3738](https://togithub.com/reflex-dev/reflex/pull/3738)
- Use `._is_mutable()` to account for parent state proxy by
[@&#8203;masenf](https://togithub.com/masenf) in
[https://github.com/reflex-dev/reflex/pull/3739](https://togithub.com/reflex-dev/reflex/pull/3739)

#### Doc Updates

- Add comments to html by [@&#8203;Alek99](https://togithub.com/Alek99)
in
[https://github.com/reflex-dev/reflex/pull/3731](https://togithub.com/reflex-dev/reflex/pull/3731)

#### Var Refactor

This release includes some new experimental features being developed
incrementally in reflex.\_x.vars.

- \[REF-3328] Implement **getitem** for ArrayVar by
[@&#8203;adhami3310](https://togithub.com/adhami3310) in
[https://github.com/reflex-dev/reflex/pull/3705](https://togithub.com/reflex-dev/reflex/pull/3705)
- add type hinting to existing types by
[@&#8203;adhami3310](https://togithub.com/adhami3310) in
[https://github.com/reflex-dev/reflex/pull/3729](https://togithub.com/reflex-dev/reflex/pull/3729)

**Full Changelog**:
reflex-dev/reflex@v0.5.8...v0.5.9

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://togithub.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOC40NC4wIiwidXBkYXRlZEluVmVyIjoiMzguNDQuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->
@masenf masenf deleted the masenf/reliable-event-actions branch December 12, 2024 07:10
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.

2 participants