Commit 7ad896e
authored
Raise if JS.dispatch detail is not a map (#4062)
Today I discovered a bug in a LiveView application where a string was
passed as the detail option to JS.dispatch instead of a map (as
documented).
It turns out it accidentally worked with the default `esbuild` config.
The bug remained unnoticed for a long time because by default `app.js`
is not compiled in JavaScript strict mode. When the config was changed
to output ESM modules (which are always in strict mode), the error
surfaced.
The exact line of code in Phoenix LiveView client code where the error is raised:
https://github.com/phoenixframework/phoenix_live_view/blob/98088bc7458d1821d9d9bb38caa3145a0b93ee9c/assets/js/phoenix_live_view/js.js#L77
Note that line has been there for many years.
This is the explanation of the error in MDN:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cant_assign_to_property
LiveView code is correct and follows the documented API. Since we
already do validations and raise on other invalid inputs, we can prevent
future mistakes by ensuring that the detail option is a map.1 parent 7654124 commit 7ad896e
File tree
2 files changed
+12
-1
lines changed- lib/phoenix_live_view
- test/phoenix_live_view
2 files changed
+12
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
366 | 366 | | |
367 | 367 | | |
368 | 368 | | |
369 | | - | |
| 369 | + | |
370 | 370 | | |
371 | 371 | | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
372 | 377 | | |
373 | 378 | | |
374 | 379 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
483 | 483 | | |
484 | 484 | | |
485 | 485 | | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
486 | 492 | | |
487 | 493 | | |
488 | 494 | | |
| |||
0 commit comments