phlex-reactive 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd797b375cedb73b2a6f5695bf38a7eddd0a939aca5f8602c661537f6407ad7b
4
- data.tar.gz: 994da28bed60c495d87d01fb736e80f19439ca52417f2c70f61a17aa7d15b351
3
+ metadata.gz: 83d418e64d127a079e74679e4920d85803fedff629e8d8b135c2896a79b5bbdd
4
+ data.tar.gz: 16c68638d96348ea94c0fa25d411486e49c0b2dab01f07fe9e67fefba630a537
5
5
  SHA512:
6
- metadata.gz: 11e13357335ec795cc5d0da9b60da2ce059128fed4f355f3864d037fbf5c0dab692844d3b8dd9d10f0b386e7bccd86ae635b2d2bc17a24e4ed1988bd37ce014e
7
- data.tar.gz: 11c0e74b06f6d55818fc65d83336d9ec77eee65422adfe477a5ebc8a83d6dda4ae6f1dad3c6fdf17a9e215cdef5bcc958bcbaa43c3e6d32b02adb15124c372e1
6
+ metadata.gz: cc16a212daaeb236631702db89fe846dabf936d532e18919c0a371d408f29ce94ae94028eff8cc82e3ff66f1ee25a8acb75f2df29f0b1e2ceb819e49ee3b7217
7
+ data.tar.gz: 0b9721189cb032d6a91ae163b15742cb1cb163ef93da4b5ced1d4382811b43da5b5ba3ea25041b5919b20fb58d2dd4d582d8c1ba1345b6d8accf7ac94cdeb978
data/CHANGELOG.md CHANGED
@@ -8,6 +8,22 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
8
8
 
9
9
  ### Fixed
10
10
 
11
+ - **Form submit navigated instead of running the reactive action.** A component
12
+ wired with `on(:save, event: "submit")` on a real `<form>` let the browser
13
+ submit natively (full POST to the form's `action`), because
14
+ `dispatch()` deferred `event.preventDefault()` into the request-queue microtask
15
+ — too late, since `preventDefault()` only works synchronously within the event
16
+ dispatch. For `click` triggers there's no default to miss, so it was invisible;
17
+ for `submit` the form navigated (e.g. `POST /` → routing error). `dispatch()`
18
+ now calls `preventDefault()` synchronously (and captures the action/params up
19
+ front, so the deferred work never re-reads a reset event object). Guarded by a
20
+ bun unit test (`spec/javascript/reactive_controller.test.js`) that asserts the
21
+ synchronous call and fails on the pre-fix deferred code. Closes #11.
22
+
23
+ ## [0.2.4] - 2026-06-24
24
+
25
+ ### Fixed
26
+
11
27
  - **Reactive save silently dropped rich-text / custom-editor fields.** The
12
28
  client's field auto-collection (`#collectFields`) queried only
13
29
  `input[name], select[name], textarea[name]`, so a named rich-text editor
@@ -123,7 +139,8 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
123
139
  scaffolds a reactive component (and an RSpec spec when the app uses RSpec),
124
140
  state-backed by default or record-backed with `--record`.
125
141
 
126
- [Unreleased]: https://github.com/mhenrixon/phlex-reactive/compare/v0.2.2...HEAD
142
+ [Unreleased]: https://github.com/mhenrixon/phlex-reactive/compare/v0.2.3...HEAD
143
+ [0.2.4]: https://github.com/mhenrixon/phlex-reactive/compare/v0.2.3...v0.2.4
127
144
  [0.2.3]: https://github.com/mhenrixon/phlex-reactive/compare/v0.2.2...v0.2.3
128
145
  [0.2.2]: https://github.com/mhenrixon/phlex-reactive/compare/v0.2.1...v0.2.2
129
146
  [0.2.1]: https://github.com/mhenrixon/phlex-reactive/compare/v0.2.0...v0.2.1
@@ -34,18 +34,24 @@ export default class extends Controller {
34
34
  // a per-controller promise makes each dispatch wait for the previous one, so
35
35
  // it always uses the freshest token.
36
36
  dispatch(event) {
37
- this.queue = (this.queue ?? Promise.resolve()).then(() => this.#perform(event))
38
- return this.queue
39
- }
40
-
41
- async #perform(event) {
42
37
  const { action, params } = event.params
43
38
  if (!action) return
44
39
 
45
- // Stop native behavior (button submit / form navigation): the reactive
46
- // round trip replaces it.
40
+ // Stop native behavior (button submit / FORM NAVIGATION) HERE, synchronously
41
+ // within the event dispatch. preventDefault() only works while the event is
42
+ // still being handled — deferring it into the request-queue microtask (below)
43
+ // is too late: a `submit` trigger would natively POST the form and navigate
44
+ // before the reactive round trip runs (issue #11). For a `click` trigger
45
+ // there's no default to miss, so this was previously invisible.
47
46
  event.preventDefault()
48
47
 
48
+ // Capture action/params now; the queued work runs in a later microtask, by
49
+ // which point the event object may have been reset by the browser.
50
+ this.queue = (this.queue ?? Promise.resolve()).then(() => this.#perform(action, params))
51
+ return this.queue
52
+ }
53
+
54
+ async #perform(action, params) {
49
55
  // Auto-collect named field values inside this component so a button-
50
56
  // triggered action still receives sibling inputs (Livewire-style).
51
57
  // Explicit params (data-reactive-params-param) win over collected fields.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Phlex
4
4
  module Reactive
5
- VERSION = "0.2.4"
5
+ VERSION = "0.2.5"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phlex-reactive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikael Henriksson