@isometriks/live_cable 0.3.0 → 0.5.0

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.
package/CHANGELOG.md CHANGED
@@ -6,6 +6,745 @@ The Ruby gem (`live_cable`) and the npm package (`@isometriks/live_cable`) are
6
6
  released together and share a single version number. Entries below note which
7
7
  side of the pair a change affects when it isn't both.
8
8
 
9
+ ## 0.5.0 - 2026-11-19
10
+
11
+ ### Upgrading from 0.4
12
+
13
+ The gem and the npm package work with each other at 0.4 in either
14
+ direction, but upgrade both to get every fix. A few fixes change behaviour an
15
+ application could notice:
16
+
17
+ - LiveCable now needs Rails 8.0 or later, and the gemspec says so. On Rails
18
+ 7.1 and 7.2, every action that takes params already failed on 0.4.
19
+ - A template that reads a local assigned inside an earlier block, with no
20
+ component method or view helper of that name, now raises `NameError`
21
+ instead of rendering nothing.
22
+ - An `<%= %>` tag, or an `if`/`case`/loop group, that assigns a top-level
23
+ local that a later tag reads before assigning it itself (a second
24
+ `for item in …` loop doesn't) now runs and is re-sent on every update, and
25
+ so is every tag that reads it. Prefer a component method for anything
26
+ costly.
27
+ - A component method named like a Kernel method (`open`, `test`, `select`, …)
28
+ now wins over Kernel in its template; call it on `Kernel`, as in
29
+ `Kernel.rand`, to reach Kernel's.
30
+ - A loading state now ends only on the component's own reply, and a nested
31
+ component's pending elements wait for it through its parent's renders. A
32
+ message held while the socket was down stays loading until it is answered.
33
+ The events an action dispatches without sending a render of its own arrive
34
+ on its `_ack`, where they used to come in a frame of their own before it.
35
+ Frames captured by `LiveCable::Testing` carry `_reply`, and subscribe frames
36
+ `_subscribed`, so a spec that compares whole frames needs those keys. An
37
+ `_ack` for a component whose new render went out inside its parent's
38
+ carries `_rendered: true`.
39
+ - A focused field keeps what the user typed through renders it didn't ask for,
40
+ and through a reply that only echoes the value its own `live-reactive`
41
+ update sent. To clear a field after a submit, bind it to a reactive variable
42
+ and reset that in the action.
43
+ - `live_mount(..., raise_errors: false)` no longer raises when the first
44
+ render or a `connect` callback fails; assert on `broadcasts(:_error)`
45
+ instead.
46
+ - In component code, changing an element held in two reactive collections
47
+ now marks the one you changed it through, not the one it was first read
48
+ from. Call `dirty(...)` for the other if the page shows it there too.
49
+ - A template now gets the plain Array, Hash or model inside a reactive
50
+ variable, and inside what a component method returns, so Rails helpers and
51
+ `case` see the real value. An Array or Hash a template changes in place, or
52
+ a model inside one, no longer marks its variable dirty; change it in the
53
+ component. `component.x` in a template still returns the tracked wrapper.
54
+ - In component code, values reached through `fetch`, `dig`, `detect`, `at`,
55
+ `min`/`max`, `min_by`/`max_by`, `sample`, `reverse_each`, a Hash's `find`
56
+ and the `each_*` iterators such as `each_slice` and `each_cons` (including
57
+ `Hash#each` and `each_value`) are tracked wrappers now, and a Hash's
58
+ `values`, `values_at` and `fetch_values` return a wrapper when they hold
59
+ nested Arrays, Hashes or models. Writes through them mark the variable
60
+ dirty. Use `to_a`, `to_h` or `LiveCable::Delegator.unwrap(value)` where
61
+ code needs the real value.
62
+ - A model stored directly in a reactive variable is watched on the record
63
+ itself, so a write through any reference to it, a `reload` that brings in
64
+ a change, or a validation that normalises an attribute marks the variable
65
+ dirty and re-renders. A model in a reactive Array or Hash re-renders on
66
+ any write made through the collection (`todos.first.title = x`,
67
+ `toggle!`, `reload`), not only `update`.
68
+ - When a component re-renders, parts that read a non-reactive `shared`
69
+ variable render again and are sent too, whether or not it changed.
70
+ - Defaults are signed in their `as_json` form, and a prerendered root renders
71
+ with that form too, so a Symbol default is a String, and a nested Hash has
72
+ String keys, on page load as well as after subscribe. In development and
73
+ test, a default that changes on the way logs a warning.
74
+ - A top-level component's default that is or holds anything other than
75
+ strings, symbols, numbers, booleans, `nil`, times, dates and permitted
76
+ params, in Arrays and Hashes, now raises `ArgumentError` on page load, in
77
+ production too. That covers an ActiveRecord record or relation, params that
78
+ aren't permitted, and a `Struct`, `Set`, presenter or form object, whether
79
+ or not it holds a record. On 0.4 the page loaded and
80
+ the component got the object's `to_s` or `inspect` string, such as
81
+ `"#<User:0x…>"`, once connected. Pass an id and load the record in the
82
+ component.
83
+ - An error raised by an initial-value lambda goes through the error handling
84
+ of the subscribe or render that first reads it instead of storing `nil`: a
85
+ root's subscribe answers with an `_error`, and a failing child replaces its
86
+ parent with the error box. An initial value other than a proc or `nil`
87
+ raises `ArgumentError` when the class loads.
88
+ - A child its parent renders now runs its render callbacks on each of those
89
+ renders. The first time a parent renders it, on page load or when an action
90
+ first shows it, they run before its connect callbacks, without connection
91
+ identifiers such as `current_user`; pass such values from the parent. A
92
+ `before_render` that throws `:abort` on that first render leaves the child
93
+ out of the page until the parent renders it again and the callback lets it
94
+ through.
95
+ - A checkbox with `live-reactive` sends `true` or `false`, and a `<select
96
+ multiple>` sends an Array of values, instead of the element's `value`.
97
+ - A render in which no part re-renders is no longer sent. An action whose
98
+ changes no part of the template reads is answered with an `_ack`, so a test
99
+ expecting a `_refresh` after one should expect `broadcasts(:_ack)`. Such an
100
+ action also no longer resets its form: a field the server doesn't track
101
+ keeps what was typed. To clear it, bind it to a reactive variable and reset
102
+ that in the action. A part that reads a non-reactive `shared` variable or a
103
+ local an earlier tag assigns re-renders whenever its component does, so a
104
+ template with one still answers with a `_refresh`.
105
+ - A relative key such as `t('.title')` in a `.live.erb` template now looks
106
+ up the template's own scope on page load, `live.counter.title` for
107
+ `app/views/live/counter.html.live.erb`, instead of the page's, such as
108
+ `home.index.title`. Move any such translations under the component's key.
109
+
110
+ ### Security
111
+
112
+ - **A child component's id could inject markup that ran in the browser.**
113
+ Over the socket a parent sends each child it renders inline as a
114
+ `<LiveCable child-live-id="...">` placeholder, and the child's id went into
115
+ that attribute unescaped. An id built from user input, such as
116
+ `live('tag', id: tag.name)`, could close the attribute and add an element
117
+ with an event handler, which ran when the client put the parent's render on
118
+ the page. An id with a plain quote broke the placeholder, so that child
119
+ never rendered. The id is now escaped in the placeholder, and the client
120
+ and the test harness read it back decoded.
121
+
122
+ ### Fixed
123
+
124
+ - **An inline child whose root element has an id broke on its first
125
+ action after the page loaded.** The client threw `TypeError:
126
+ rootNode.querySelectorAll is not a function` and the child didn't update.
127
+ The parent's first render over the socket brings the child's template, and
128
+ the client stored it with the element that render built. But the morph
129
+ kept the page's own element, because its id matched, so when the child's
130
+ controller connected on that element its subscription started empty. The
131
+ server only confirmed the subscription, since it had already sent the
132
+ template, and the child's first update arrived as a delta with nothing to
133
+ apply it to. A subscription now takes the state its parent's render left
134
+ for it, whichever element the controller connected on (npm).
135
+ - **A template local could render blank or stale.** Dependency tracking
136
+ parsed each part of a `.live.erb` template on its own and ignored Ruby's
137
+ block scopes. A local assigned inside a block leaked into later parts, so a
138
+ later `<%= css %>` rendered blank instead of calling the component's `css`;
139
+ a top-level local updated inside a block, as in
140
+ `<% counts.each { |c| total += c } %>`, kept its earlier value in later
141
+ parts; a local reassigned in an `if` that didn't run became `nil`; and a
142
+ tag that read a local by hash shorthand (`total:`), or one set by multiple
143
+ assignment, pattern matching or a named regex capture, never re-rendered.
144
+ Block parameters also counted as dependencies, so a part re-rendered
145
+ whenever a reactive variable of the same name changed. And only a lone
146
+ `<% %>` tag always ran, so a local first assigned inside an `if`, `case` or
147
+ `for`, or in an `<%= %>` tag, was `nil` in a later part that re-rendered
148
+ while that tag was skipped. Each part is now parsed with the earlier parts'
149
+ locals in scope, so names resolve as they would in a plain ERB template,
150
+ and a part that assigns a top-level local a later tag reads always runs. Two
151
+ templates behave differently: one that reads a block's local after the
152
+ block, with no component method or view helper of that name, now raises
153
+ `NameError`, as plain ERB does, instead of rendering nothing; and a local
154
+ reassigned in a branch that doesn't run keeps its value instead of becoming
155
+ `nil` (gem).
156
+ - **A block passed to a view helper that renders a partial landed above the
157
+ partial.** A helper such as
158
+ `def card(&) = render(layout: 'shared/card', &)`, used from a `.live.erb`
159
+ template as `<%= card do %>`, wrote the block's content before the card and
160
+ left stray escaped markup where the card yields. A presenter or any other
161
+ object that renders a partial with the template's block did the same.
162
+ 0.4.0 fixed this only for `render` called by the template itself. A block
163
+ in a `.live.erb` template now writes wherever the view is writing when it
164
+ runs, as in plain ERB, so it lands where the partial yields. Helpers that
165
+ capture their block, such as `form_with` and `content_tag`, work as before
166
+ (gem).
167
+ - **The error for a `.live.erb` template rendered as a partial didn't say
168
+ which template.** The message began "A .live.erb template", and the
169
+ backtrace points into LiveCable rather than at the template. It now opens
170
+ with the template's path, such as
171
+ `app/views/shared/_live_card.html.live.erb` (gem).
172
+ - **Template names that Kernel or Object also define, like `open`, `select`
173
+ or `test`, ran the Kernel method instead of the component's or the view
174
+ helper's.** A `.live.erb` template resolves bare names to the component and
175
+ then the view context, but names the renderer already had from Kernel or
176
+ Object never got that far. A component with `reactive :open` and
177
+ `<% if open %>` raised an `ArgumentError` on the page and on mount, the
178
+ `select` form helper raised a `TypeError`, and `j` printed to standard
179
+ output instead of escaping. These names now go to the component or the view
180
+ context whenever either defines them. When neither does they still call the
181
+ Kernel method, so `format`, `rand` and `lambda` work as before. A component
182
+ method with such a name now wins in its template; call it on `Kernel`, as
183
+ in `Kernel.rand`, to reach the Kernel method. Names the renderer used for
184
+ its own state hid the component's in the same way: with `reactive :parts`,
185
+ `<%= parts %>` printed the compiled template, and with `reactive :changes`,
186
+ `changes` returned the variables being re-rendered. Those now reach the
187
+ component too (gem).
188
+ - **A child hidden after its parent re-rendered something else was never
189
+ destroyed.** A parent only remembered the inline children of the parts its
190
+ last render had run, so after a render that skipped a child's part it no
191
+ longer knew it had that child. That happened on any change the part doesn't
192
+ depend on, and whenever the parent was re-rendered inline by its own parent
193
+ with nothing changed. Hiding the child later, a render error in the parent,
194
+ or the parent's own destroy then left the child subscribed, with its
195
+ `stream_from` streams running, until the socket closed. A compound component
196
+ that switched to a variant with fewer parts leaked the children of the parts
197
+ that went away in the same way. A parent now keeps the children of the parts
198
+ a render skipped, and destroys any its new template no longer renders (gem).
199
+ - **A `stream_from` callback could still run after `stop_stream`.**
200
+ ActionCable runs each broadcast as its own job on its worker pool, and
201
+ stopping a stream can't take back a job already queued. A chat that
202
+ switched rooms with `stop_stream` and a new `stream_from` could still run a
203
+ callback for the old room after the switch. With a reactive array, the old
204
+ room's message was appended to the new room's list and stayed there. A
205
+ callback now checks, under the connection lock, that its stream is still
206
+ running, so once `stop_stream` returns none of its callbacks run. Stopping a
207
+ stream and starting it again under the same name still delivers what was
208
+ already queued. `stop_stream` also kept every name it had stopped, a list
209
+ that grew with each switch. The new `stop_stream_from(name)` stops one
210
+ stream and leaves the component's others running (gem).
211
+ - **Another user's broadcast re-enabled a `live-disable-with` button whose own
212
+ message was still in flight.** The client ended a component's loading state
213
+ on every `_refresh`, including renders it never asked for - a `stream_from`
214
+ callback's, or one caused by another component's action - and a parent's
215
+ re-render rebuilt a nested component's pending button, so someone else's
216
+ chat message could re-enable your Send button and invite a double submit. A
217
+ nested component re-rendered only inside its parent's render got no reply at
218
+ all, and stalled after 30 seconds. The server now marks the render that
219
+ answers a message with `_reply`, or sends an `_ack` when the component sent
220
+ no render of its own, marked `_rendered` when its new render went out inside
221
+ its parent's. The client ends a loading state only on a reply, an `_ack` or
222
+ an `_error`. A render an action pushes with `broadcast_render` before it
223
+ returns isn't the reply. An `_ack` carries the events its message
224
+ dispatched, so their handlers run once the loading state has ended and the
225
+ component has caught up. Pending elements, and the `live-loading` on a
226
+ nested component's root, keep their state through other renders, even a
227
+ parent's render that carries the nested component's own, and catch up when
228
+ the loading state ends, whether by the answer, the socket closing, a
229
+ re-subscribe, a stall or a parent's render that moves the nested component,
230
+ as reordering a list does. An `_ack` now also turns a `stalled` status back
231
+ to `subscribed`, as a `_refresh` did. Frames captured by
232
+ `LiveCable::Testing` carry the new `_reply`, `_subscribed` and `_rendered`
233
+ keys. A message held while the socket was down now stays loading until its
234
+ own reply, and one lost with the socket stops when it closes or the
235
+ component re-subscribes.
236
+ Either side works with the other at 0.4.0.
237
+ - **Typing in a focused field was undone by renders that arrived while the
238
+ user typed.** Every refresh is morphed in from HTML rebuilt from the
239
+ component's stored parts, which set each field back to the last value the
240
+ server rendered. In a chat with a debounced `live-reactive` draft, an
241
+ incoming `stream_from` message, a render caused by another component, or the
242
+ reply to the draft's own last update dropped what had been typed since that
243
+ update, and the debounced send that followed sent what was left. A focused
244
+ field - a textarea, or any input a user types into or sets with a picker or
245
+ slider, such as text, number, date or range - now keeps what has been
246
+ entered unless the server changed its value. A re-render that answers the
247
+ field's own form or action still applies the server's value, so an input
248
+ cleared after a submit is still cleared, but a reply that only echoes the
249
+ value the field's own `live-reactive` update sent keeps what has been typed
250
+ since. Unfocused fields, checkboxes, radios and selects behave as before. A
251
+ focused field that isn't bound to a reactive variable is no longer cleared
252
+ by a render it didn't ask for; to clear it after a submit, bind it and reset
253
+ the variable in the action (npm).
254
+ - **A Turbo Drive visit removed the inline children of a component that stayed
255
+ on the page.** Before Turbo renders a new page, LiveCable closes the
256
+ subscription of every component that isn't on it. The HTTP prerender gives a
257
+ live id only to the root component, so a child rendered inline by its parent
258
+ looked like it was leaving, even when the parent (a layout component, say)
259
+ was staying. The child was torn down on the server, and the parent had
260
+ nothing to rebuild it from, so it disappeared from the page. A component
261
+ that stays on the page with the same defaults now also keeps the children it
262
+ renders with `.live.erb` templates, and theirs, with their subscriptions and
263
+ live state. One the new page renders with different defaults is still built
264
+ again from them, and its children with it, unless it is in a
265
+ `data-turbo-permanent` element that Turbo carries over: Turbo keeps the
266
+ element already on the page, so the component and its children keep their
267
+ state (npm).
268
+ - **`live_mount(..., raise_errors: false)` still raised when the first render
269
+ or a `connect` callback failed.** `live_mount` ran `connect` and the first
270
+ render with no rescue, so an error in either still raised, while production
271
+ sends it through the connection's error handling and transmits an `_error`.
272
+ `live_mount` now handles those errors the same way `LiveChannel#subscribed`
273
+ does. With `raise_errors: false` it returns the component with the `_error`
274
+ in its broadcasts, so a spec that expected it to raise now needs to assert
275
+ on `broadcasts(:_error)` instead. The default, `raise_errors: true`, still
276
+ raises (gem).
277
+ - **`component.x` and `self.x` in a template didn't re-render when `x`
278
+ changed.** Dependency tracking only recorded bare names, so a part that read
279
+ a reactive variable as `component.theme` or `self.theme` was skipped when
280
+ `theme` changed and kept showing the old value. `self.x` also ran Kernel's
281
+ method of that name when there was one, so `self.open` raised. Both forms
282
+ now count as reads of the component (gem).
283
+ - **A call to a helper or component method rendered a template local of the
284
+ same name instead.** After `<% t = Time.current %>`, a later
285
+ `<%= t('.title') %>` printed the time, and after `<% count = 99 %>`,
286
+ `count()` and `self.count` printed 99 instead of calling the component's
287
+ `count`. A local is now read only by its bare name, as in plain ERB (gem).
288
+ - **`items.each.with_index` raised `LocalJumpError` on reactive arrays.** A
289
+ reactive array's `each` always yielded, so calling `each` without a block
290
+ failed, and so did `each.with_index`, `each.with_object` and `each.lazy`. In
291
+ a template this meant the prerender worked, because it sees the raw array,
292
+ but every socket render failed and the component never went live. `each`
293
+ without a block now returns an enumerator, and elements yielded through it
294
+ are tracked like those from `each` with a block (gem).
295
+ - **`self.tags = tags.dup` stopped all later change tracking for `tags`.**
296
+ `dup` dropped the wrapper's tracking modules, so the assignment rendered
297
+ once and every later `tags << x` or nested change went unnoticed. A
298
+ duplicated reactive value now keeps its tracking. `clone(freeze: false)` on
299
+ a reactive value or an ActiveRecord model raised `ArgumentError` and now
300
+ works (gem).
301
+ - **Changing an element moved into another reactive collection marked the
302
+ wrong variable.** After `done << todos.find { ... }` (or `self.done =
303
+ [item]`, `done + [item]`, `selection[:item] = item`), changing the element
304
+ through `done` marked `todos` instead. That included a child component given
305
+ the element with `live(...)`, so the `done` part never re-rendered. Reactive
306
+ collections now store the plain element rather than the tracked wrapper it
307
+ was read through, and an element read back is tracked through the collection
308
+ it was read from. In component code, an element kept in both collections is
309
+ tracked through the one it is changed through, so a change through `done` no
310
+ longer marks `todos`; call `dirty(:todos)` if both show it. An element read
311
+ from a reactive collection and passed back to one of its mutators, as in
312
+ `todos.delete(todos.find { ... })` on a list of models, is now found. An
313
+ Array or Hash you pass in is copied only when it holds such a wrapper
314
+ (gem).
315
+ - **After connecting, reactive Arrays and Hashes rendered wrongly in Rails tag
316
+ helpers, and `where(id: reactive_array)` matched nothing.** A tracked value
317
+ isn't an `Array` or `Hash` to `case` or `===`. On socket renders,
318
+ `tag.span(class: classes)` printed `class="[&quot;btn&quot;,
319
+ &quot;primary&quot;]"` where the prerender printed `class="btn primary"`,
320
+ and `where(id: ids)` compiled to `id = NULL`. Templates now see the plain
321
+ value, also inside an Array or Hash a component method builds from reactive
322
+ values (`[todos.first, todos.last]`), so helpers and `case` behave as in any
323
+ Rails view, and `where(column: value)`, `where(association: records)`,
324
+ `in_order_of` and Arel's `in` and `not_in` accept reactive values instead of
325
+ matching nothing. A child given one of these with `live(...)` still shares
326
+ its change tracking, so the parent re-renders when the child changes it.
327
+ That covers a reactive value, an element of one, and a collection built from
328
+ one in the template or a component method. A child first rendered while two
329
+ reactive collections hold an element marks both. An Array or Hash changed in
330
+ place in a template, or a model inside one, no longer marks its variable
331
+ dirty. A variable's first read now returns the tracked value like later
332
+ reads, so changes made through it are tracked. `find`, `destroy` and
333
+ `update` given a reactive list of ids act on every id instead of one.
334
+ Component code sees plain values during the HTTP prerender and wrappers once
335
+ connected, so for `case`, `where(hash)` and association assignment it needs
336
+ `to_a`, `to_h` or `LiveCable::Delegator.unwrap(value)`, which work in both
337
+ (gem).
338
+ - **Some common ways of changing a reactive Array or Hash didn't re-render.**
339
+ Change tracking only knew the method names it listed, so aliases and
340
+ ActiveSupport bang methods went straight through untracked. That covered
341
+ `append`, `prepend`, `filter!`, `collect!`, `compact_blank!` and `extract!`,
342
+ and on hashes `store`, `replace`, `slice!`, `with_defaults!`,
343
+ `deep_symbolize_keys!` and others. Nested values read through `detect`,
344
+ `fetch`, `dig`, `at`, `min_by`, `each_with_index`, `each_with_object`,
345
+ `reverse_each`, `each_slice`, `values`, `each_value` or `Hash#each` came
346
+ back untracked. So `todos.detect { ... }[:done] = true` answered with an
347
+ `_ack` and left the page stale. All of these are now tracked, and a spec
348
+ fails if a bang method, or an alias of a tracked one, is left out. Values
349
+ these methods return or yield are now tracked wrappers, like the ones
350
+ `each` already yielded, so in component code `is_a?(Hash)` on them is
351
+ false. The elements passed to the blocks of `map`/`select`, the results of
352
+ methods that don't wrap what they return (a Hash's `select` or `slice`, an
353
+ Array's `second` or `partition`) and `to_a`/`to_h` are still untracked; see
354
+ *Nested Structures* in the reactive variables guide (gem).
355
+ - **`where(commentable: record)` with a reactive record dropped the
356
+ `commentable_type` condition and returned other models' rows.** ActiveRecord
357
+ finds a polymorphic association's type with `is_a?(ActiveRecord::Base)`,
358
+ which the wrapper answers false, so the query became
359
+ `WHERE commentable_id = 1` and matched rows of every model with that id;
360
+ `where.not` hid them instead. A plain Array holding reactive records, as in
361
+ `where(id: [first, last])`, matched nothing. The predicate builder now
362
+ unwraps reactive values, including those inside an Array, before
363
+ ActiveRecord expands the hash (gem).
364
+ - **ActiveRecord models read from a reactive variable never compared equal.**
365
+ Two reads of the same record, or a raw record and a wrapped one, compared
366
+ unequal. So `list.delete(found)` on a plain Array left the record in it,
367
+ `include?`, `index` and `todos - [found]` missed it, and `t == selected` in
368
+ a template never matched. Equality now compares the records themselves.
369
+ Unsaved records still compare unequal, as ActiveRecord intends (gem).
370
+ - **Many changes to ActiveRecord models in reactive variables didn't
371
+ re-render.** A model reached through a reactive Array or Hash
372
+ (`todos.first.title = x`, `todos.find { ... }.toggle!(:done)`, setters
373
+ inside `todos.each`) was only tracked for `update` and `assign_attributes`.
374
+ Even a model stored directly missed `[]=`, `write_attribute`, `increment!`,
375
+ `update_column(s)`, `reload` and saved in-place JSON changes, so the
376
+ streaming guide's `document.reload` example never refreshed the page. All of
377
+ these writes are now tracked, at any depth. A replaced record no longer
378
+ keeps marking the variable it was removed from. A `reload` re-renders only
379
+ when the record's columns changed, so reloading to check a record before
380
+ writing costs nothing; validations that normalize attributes re-render even
381
+ when nothing visible changed.
382
+ Association changes and unsaved in-place edits still need `dirty(:name)`
383
+ (gem).
384
+ - **Writes through the `clone` of a model in a reactive variable didn't
385
+ re-render.** ActiveRecord's `clone` shares the original's attributes, so
386
+ `todo.clone.title = 'b'` changed the stored record, but the copy dropped
387
+ the original's change tracking and the page kept the old title. A clone of
388
+ a tracked model, held directly or read from a reactive Array or Hash, now
389
+ marks the same variables; a `dup` is still a separate, untracked record
390
+ (gem).
391
+ - **A part that passed a reactive variable with hash shorthand (`render
392
+ 'badge', page:`) or called it with empty parentheses (`count()`) never
393
+ re-rendered.** The dependency analysis only recognised a bare `page`, so
394
+ these forms (`tag.span(data: { page: })`, `items_path(page:)`) were left
395
+ out and the part kept its first-render HTML. Any receiverless call with no
396
+ arguments and no block now counts as a read (gem).
397
+ - **A component method's dependencies were lost when another def in the same
398
+ file had the same name.** The method analyzer parses the component's whole
399
+ file and the last def with a given name won, so a `def self.title`, a
400
+ `class << self` method, a method in a nested class or `Struct.new` block, or
401
+ a method of a second class in the file could leave every part calling
402
+ `title` stale. Same-named defs now merge their dependencies, and singleton
403
+ methods are ignored. Affected parts may now re-render where they were
404
+ previously skipped (gem).
405
+ - **Parts reading a non-reactive `shared` variable in a `.live.erb` template
406
+ never re-rendered.** They kept their first-render value even when the
407
+ component re-rendered for its own reasons, including in an action that also
408
+ wrote the variable, so the guide's FilterPanel badge example showed a stale
409
+ count. Whenever a component re-renders, parts that read its `shared`
410
+ variables, directly or through a component method, now re-render too. A
411
+ change to a `shared` variable on its own still does not trigger a render of
412
+ the components that declare it with `shared`. These parts are now sent on
413
+ every re-render of the component (gem).
414
+ - **The guide's `reactive :user, ->(c) { User.find(c.defaults[:user_id]) }`
415
+ raised `NoMethodError`.** `Component#defaults` was private, and an initial
416
+ lambda gets the component as an explicit receiver. So the prerender failed,
417
+ `live_mount` raised, and a real subscribe sent an `_error` and rendered
418
+ without the default. `defaults` is now public. As a side effect, a bare
419
+ `defaults` in a `.live.erb` template now resolves to the component's hash
420
+ (gem).
421
+ - **A top-level component could render one way on page load and another once
422
+ connected.** Its defaults come back from the browser as JSON on subscribe,
423
+ but the prerender used the raw Ruby values. A Symbol came back as a String
424
+ and nested hash keys as Strings. Since signing in 0.4.0 used plain
425
+ `JSON.generate`, a `Time` came back as its `to_s` and a record as
426
+ `"#<User:0x…>"`. LiveCable now signs each default's `as_json` form, as 0.3's
427
+ unsigned attribute did, and prerenders a top-level component with that same
428
+ form, so both renders agree: `status: :open` is now `"open"` on page load
429
+ too. The defaults are signed, not encrypted, and a record's JSON form is
430
+ every one of its attributes, and a plain object's is its instance variables,
431
+ so a top-level component given anything other than strings, symbols,
432
+ numbers, booleans, `nil`, times, dates and permitted params (which arrive as
433
+ a Hash), in Arrays and Hashes, now raises `ArgumentError` on page load in
434
+ every environment. That covers a record or
435
+ relation, and a `Struct`, `Set` or presenter holding one. Pass its id and
436
+ load the record in the component. In development and test, a Symbol, Time or
437
+ other default that comes back changed logs a warning. Children rendered by a
438
+ parent and `live_mount` defaults are unchanged (gem).
439
+ - **An exception in a reactive variable's initial lambda was swallowed and the
440
+ variable stuck at `nil` (or `true`).** On a connected component the error
441
+ was reported, and then `handle_error`'s return value was stored as the
442
+ variable. That was `nil` for a child rendered inline and `true` for a
443
+ component with a channel, and the lambda never ran again. A child whose
444
+ lambda failed rendered blank, with nothing sent to the client, and a failed
445
+ shared variable stayed broken for every later sharer. The error now goes
446
+ through the error handling of the subscribe or render that first reads it,
447
+ and nothing is stored, so the next read retries. A top-level component's
448
+ subscribe now sends just the `_error` (no trailing `_refresh`). A child's
449
+ failing initial value now replaces its parent with the error box. An initial
450
+ value other than a proc or `nil` now raises `ArgumentError` when the class
451
+ loads (gem).
452
+ - **Initial lambdas ran again on every read during the HTTP prerender.** With
453
+ no connection, the reactive getter never kept the value, so a `.live.erb`
454
+ template ran the lambda once per reference, plus once for the render locals.
455
+ A query read three times ran four times, and `-> { SecureRandom.hex }` gave
456
+ a label's `for` and its input's `id` different values on the same page. The
457
+ value is now kept for the rest of that prerender (gem).
458
+ - **`before_render` and `after_render` never ran for a child rendered by its
459
+ parent.** Render callbacks ran only when a component broadcast its own
460
+ render. A child rendered inside a connected parent was never rendered that
461
+ way: on page load its subscription found it already rendered and only
462
+ confirmed its status. So state a child derived in `before_render` showed its
463
+ initial value and went stale every time the parent rendered it again. A
464
+ child's render callbacks now run each time a connected parent renders it,
465
+ and an error in one replaces the parent with the error box. A
466
+ `before_render` that throws `:abort` keeps the child as it last rendered, or
467
+ leaves it out the first time the parent renders it, until the parent renders
468
+ it again and the callback lets it through. A grandchild that changed along
469
+ with its grandparent, or a child whose parent subscribed again, is no longer
470
+ also rendered on its own in the same update, so its callbacks run once. When
471
+ a callback halts a parent's own render, a child that changed now renders on
472
+ its own instead of being skipped. The first time a connected parent renders
473
+ a child, on page load or when an action first shows it, the child hasn't
474
+ subscribed yet, so its render callbacks run before its connect callbacks,
475
+ without connection identifiers such as `current_user`. A child whose
476
+ `before_render` uses one will now error its parent the first time the parent
477
+ renders it. Render callbacks still don't run during the HTTP prerender,
478
+ which the lifecycle guide now says (gem).
479
+ - **A checkbox with `live-reactive` could never be unchecked, and a `<select
480
+ multiple>` kept only its first choice.** `live-reactive` always sent the
481
+ input's `value`. For a checkbox that is its `value` attribute ("on" by
482
+ default), whether the box is checked or not. For a multiple select it is
483
+ only the first selected option. A checkbox now sends `true` or `false`, and
484
+ a `<select multiple>` sends an Array of the selected values. Radios, single
485
+ selects and text inputs still send their value as a String. If you were
486
+ reading "on" (or a custom `value` attribute) from a checkbox, you now get a
487
+ boolean (npm).
488
+ - **A `live-disable-with` button lost the markup in its label when an `_ack`
489
+ answered its message.** The label was saved and restored as text, which
490
+ flattened an icon or a `<span>` inside it. A `_refresh` reply rebuilds the
491
+ button from the stored render and hid that, but an `_ack` leaves the page
492
+ alone, and since a render in which no part re-renders is no longer sent,
493
+ more actions are answered with one: an icon in a click counter's button was
494
+ gone after the first click. The label is now saved and restored as HTML
495
+ (npm).
496
+ - **Every action on a component with `reactive :method` raised
497
+ `ArgumentError`.** The action was looked up with the component's `method`,
498
+ which the reactive variable's getter replaces. It is now looked up with
499
+ Kernel's `method`, so a reactive variable named `method` works (gem).
500
+ - **`t('.key')` in a component template raised over the socket and used the
501
+ page's scope on page load.** Rails scopes a relative key by the template
502
+ being rendered, but it only knows that while the template's compiled method
503
+ runs, and a `.live.erb` template's parts run after it returns. Over the
504
+ socket there was no template at all, so the lookup raised "Cannot use
505
+ t(".key") shortcut because path is not available"; on page load it used
506
+ the page's path, so `t('.title')` looked up `home.index.title`. Each
507
+ render of a component template now runs its parts with that template's
508
+ path, so a relative key resolves to the template's own scope, such as
509
+ `live.counter.title`, in a child component and in each template of a
510
+ compound component too (gem).
511
+
512
+ ### Changed
513
+
514
+ - **The gemspec allowed Rails 7.1 and 7.2, where every action that takes
515
+ params raised `NameError`.** LiveCable parses action params with
516
+ `ActionDispatch::ParamBuilder` and `ActionDispatch::QueryParser`, which
517
+ Rails 8.0 added. The gem now requires Rails 8.0 or later, and the
518
+ installation guide, which said 7.1, says so (gem).
519
+ - **A render that changed nothing on the page was still sent.** When a
520
+ reactive variable changed but no part of the template showed it - a shared
521
+ variable updated by another component, say - the component still sent a
522
+ `_refresh` with every part empty, and the client rebuilt and morphed it for
523
+ no visible change. A render in which no part re-renders is now skipped: its
524
+ events still go out, its render callbacks still run, and the message it
525
+ answers gets an `_ack`, which carries the events of the component that sent
526
+ the message. An action answered this way no longer resets its form: a field
527
+ the server doesn't track keeps what was typed. A part that reads a
528
+ non-reactive `shared` variable or a local an earlier tag assigns re-renders
529
+ whenever its component does, so a template with one still sends a
530
+ `_refresh` (gem).
531
+ - **Every render over the socket went through a full controller render.**
532
+ `Component#render` used `ApplicationController.renderer`, which builds a
533
+ controller, request and response and renders through `render_to_string`
534
+ each time, about a sixth of the time of an action on a small component. A
535
+ connection now builds the request and response once, from the renderer's
536
+ current defaults, and each render calls the component's `render_in` on a
537
+ fresh controller and view, so nothing one render sets or memoizes on them
538
+ carries over to the next. A component with a public `format` method no
539
+ longer fails every socket render with `ArgumentError` (Invalid formats). The
540
+ HTTP prerender is unchanged (gem).
541
+
542
+ ## 0.4.0 - 2026-09-29
543
+
544
+ ### Upgrading from 0.3
545
+
546
+ Upgrade the gem and the npm package together. Defaults are now signed, and
547
+ the client forwards them as an opaque string; a 0.3 client sends them as an
548
+ object, which the server treats as no defaults at all, so every component
549
+ would mount without them.
550
+
551
+ Pages rendered before the upgrade carry unsigned defaults too. They mount with
552
+ no defaults until reloaded, so deploy at a quiet moment, or expect components
553
+ on open tabs to come up empty.
554
+
555
+ A component already live on the page is now built again when a Turbo visit
556
+ renders it with different defaults. One whose defaults differ on every
557
+ render - a timestamp, a random token - is therefore rebuilt on every visit
558
+ instead of keeping its state; keep defaults to what the component is about,
559
+ such as a record or an account.
560
+
561
+ A shared variable is now writable from the client only if every component
562
+ class that shares the name declares it `writable: true`. An application that
563
+ shares a name as writable in one component and server-only in another will
564
+ see `live-reactive` writes to it refused.
565
+
566
+ ### Security
567
+
568
+ - **Defaults could set reactive variables that weren't writable.** Defaults
569
+ passed to `live(...)` are written into the page and sent back by the browser
570
+ when the component subscribes, and they were applied to any reactive
571
+ variable, writable or not. Anyone could edit the `live-defaults` attribute,
572
+ or send the subscribe frame by hand, and set a variable meant to be
573
+ server-only - a record id, a price, a tenant key - bypassing the check
574
+ `live-reactive` writes go through. Defaults are now signed with a key
575
+ derived from `secret_key_base` and bound to the component's `live_id`; an
576
+ edited, unsigned or borrowed blob applies no defaults
577
+ (`LiveCable::DefaultsSigner`). `LiveCable::Testing#live_mount` still takes a
578
+ plain hash.
579
+ - **A component could keep acting for the previous page's defaults after a
580
+ Turbo visit.** When the new page rendered a component with the same id as
581
+ one already live, the client kept the existing subscription and never sent
582
+ the new page's defaults. A component whose id didn't include the account
583
+ stayed bound to the account it was first rendered for, and its actions ran
584
+ against that account under a URL for another. The client now compares the
585
+ signed defaults and, when they differ, replaces the subscription so the
586
+ server builds the component from the new ones; equal defaults keep today's
587
+ behaviour, state included. A Turbo preview of a cached page is ignored.
588
+ Defaults are signed with their keys sorted, so the same defaults always
589
+ produce the same blob.
590
+ - **A client could write a shared variable that a component treats as
591
+ server-only.** Shared variables are one value per connection, but a
592
+ `live-reactive` write was checked only against the class it was sent
593
+ through. Because a client can subscribe any component, it could mount one
594
+ that shares `:account_id` as `writable: true` and set the value another
595
+ component shares without `writable:` (or with plain `shared`). A client may
596
+ now write a shared name only if every class that shares it declares it
597
+ `writable: true`. Other writes are refused with `Forbidden`. Apps that mix
598
+ writable and server-only declarations of the same shared name will see those
599
+ writes refused. In development with lazy loading, a class that hasn't loaded
600
+ yet doesn't count toward the rule (gem).
601
+
602
+ ### Fixed
603
+
604
+ - **An action and a `stream_from` callback could run at the same time on one
605
+ connection.** ActionCable runs each message and each stream broadcast as a
606
+ separate job on a worker pool shared by the whole server, with nothing
607
+ keeping two jobs for one socket apart, and LiveCable's per-connection state
608
+ was read and written from both. An action that saved a record and then
609
+ pushed it onto a reactive array could have the save's own broadcast reload
610
+ the array in between, and the record appeared twice. Each connection's work
611
+ is now serialised by a re-entrant lock, held across an action or callback
612
+ and its render. A job waiting on a busy connection holds a worker while it
613
+ waits; see *Concurrency* in the architecture guide (gem).
614
+ - **A click while the socket was down left its button disabled for good.**
615
+ ActionCable drops a message sent on a closed socket, and one sent after a
616
+ reconnect but before the re-subscribe is confirmed, and the loading state
617
+ had already started. Messages are now held until the subscription is
618
+ confirmed and sent in order, and the component reads
619
+ `data-live-status-value="disconnected"` meanwhile (npm).
620
+ - **A loading state waited for ever when no reply came** - the server
621
+ stopping mid-message, on a deploy. After `LoadingState.timeout` (30 seconds)
622
+ with nothing heard it gives up, restores the DOM, drops any messages still
623
+ held for a reconnect, sets the status to `stalled` and dispatches a
624
+ `live:stalled` event. Messages still held when a component's element is
625
+ replaced, by a Turbo navigation say, keep their loading state on the new
626
+ element (npm).
627
+ - **Events dispatched by a child rendered inline by its parent were dropped.**
628
+ Such a child has no channel of its own yet; its events were flushed and then
629
+ discarded. They now wait for the child's own subscription (gem).
630
+ - **Component names that collide with a top-level constant failed obscurely.**
631
+ `instance_from_string` used `const_defined?`, which inherits, so a name like
632
+ `"string"` slipped past the "not found" guard and raised `NoMethodError`
633
+ instead of `LiveCable::Error` (gem).
634
+ - **A `stream_from` callback re-sent whatever the last message had changed.**
635
+ Changesets were reset only when a client message arrived. Variables dirtied
636
+ by the last message, or by the defaults applied at subscribe, stayed dirty,
637
+ and every later stream callback on the socket re-rendered them, whichever
638
+ component of the connection they belonged to. In a chat whose input is a
639
+ component of its own, as in the streaming guide, each incoming message
640
+ re-rendered the input with its last-sent `live-reactive` value, and the
641
+ morph overwrote whatever had been typed since the last debounce. A stream
642
+ callback now resets the changesets before it runs, as a message does, so it
643
+ sends only what it changed (gem).
644
+ - **Grandchild components went missing from the page.** A refresh replaced
645
+ the `<LiveCable>` placeholders in its own markup but not the ones inside a
646
+ child it had just built or rebuilt, so a grandchild reached the morph as an
647
+ empty element: a tree nested three deep lost its third level as soon as the
648
+ page connected, and a grandchild added by its parent's own refresh was torn
649
+ out the next time its grandparent re-rendered. Placeholders are now
650
+ replaced until none remain. A component that turns up twice in one refresh
651
+ keeps its first appearance and logs a console error, and a child with
652
+ nothing to rebuild from is left empty instead of abandoning the refresh
653
+ (npm).
654
+ - **Rendering a partial with a block from a `.live.erb` template failed.**
655
+ The block was dropped on its way to the view, so
656
+ `<%= render layout: 'shared/card' do %>` raised `ArgumentError`, and
657
+ `<%= render 'shared/card' do %>` rendered the partial with nothing where it
658
+ yields. The block is now passed on and renders where the partial yields (gem).
659
+ - **Rendering a `.live.erb` template as a partial put
660
+ `#<LiveCable::Rendering::Partial:0x...>` in the page.** A `.live.erb`
661
+ template compiles to an object only a component knows how to render, so
662
+ `<%= render 'shared/card' %>` on a `_card.html.live.erb`, or
663
+ `render template:` on one, wrote that object's escaped name into the HTML.
664
+ It now raises `LiveCable::Error`, saying to render the component with
665
+ `live(...)` or `render(component)`, or to make the partial a `.html.erb`
666
+ template (gem).
667
+ - **A `stream_from` broadcast that arrived as its component disconnected
668
+ raised in ActionCable's worker.** ActionCable runs each broadcast as its own
669
+ job, so one queued before the stream was stopped still ran the callback
670
+ against the departed component; broadcasting its changes then raised
671
+ `NoMethodError` on the missing connection, and the rescue meant to report
672
+ that raised again, so the error escaped to ActionCable's log. Such a
673
+ callback is now ignored (gem).
674
+ - **The test harness's `rendered` forgot the initial render after
675
+ `clear_broadcasts`.** It was rebuilt from the `_refresh` payloads still in
676
+ the broadcast log, so after a clear and an action it held only the parts
677
+ that action changed, and any inline child rendered earlier was missing.
678
+ Renders are now kept apart from the broadcast log, so `rendered` and
679
+ `rendered_html` reflect every render whatever has been cleared.
680
+ `broadcasts` and `dispatched_events` still start over after a clear (gem).
681
+ - **The test harness's `rendered` left out grandchildren.** The results
682
+ for inline children at every depth arrive together in the root's refresh,
683
+ but a child's placeholders were resolved against a set of children of its
684
+ own, which was always empty. A component rendered inline by an inline child
685
+ came out blank. Placeholders now resolve at any depth (gem).
686
+ - **Two components that subscribed at the same moment could end up on
687
+ different connections.** A socket's `LiveCable::Connection` is created the
688
+ first time it is needed, and ActionCable runs each subscribe as its own job
689
+ on its worker pool, so two components on one page subscribing together could
690
+ each create one. A component left on the losing one had its actions answered
691
+ with an `_ack` and no re-render, and shared reactive variables weren't
692
+ shared. The connection is now created under a lock (gem).
693
+ - `MethodAnalyzer` no longer raises for a component class with no Ruby source
694
+ location, such as one built with `Class.new`. With no methods to analyze,
695
+ every part that calls one of the component's methods re-renders on each
696
+ change (gem).
697
+ - `insert_root_attributes` builds a new string instead of mutating the
698
+ rendered part, so a frozen part can't raise `FrozenError`, and its "no root
699
+ element" error now shows the start of the offending output (gem).
700
+ - **A component destroyed while a message was in flight stayed loading.**
701
+ `destroy` unsubscribes the component on the client, so the reply to the
702
+ message that caused it never arrived and its `live-disable-with` button
703
+ stayed disabled. The loading state is now cleared when the server destroys
704
+ the component (npm).
705
+
706
+ ### Added
707
+
708
+ - **`rescue_from` in components.** `ActiveSupport::Rescuable` was included but
709
+ never consulted. An error raised by an action, a `live-reactive` write or a
710
+ `stream_from` callback is now offered to the component's `rescue_from`
711
+ handlers first; a handled error still answers the message, so the loading
712
+ state clears, and anything the handler set is re-rendered. Failures while
713
+ subscribing or rendering still get the default error markup, as does a
714
+ message asking for an action the component doesn't expose or a write to a
715
+ variable that isn't `writable:` - those raise `LiveCable::Forbidden`, a
716
+ `LiveCable::Error`, and are never offered to `rescue_from` (gem).
717
+ - **`before_dispatch` callbacks.** Authorizing every client message meant
718
+ wrapping each action, keeping its arity, catching methods defined after
719
+ `actions`, and wrapping every writable variable's setter - which then also
720
+ ran for the component's own writes. `before_dispatch` runs before each
721
+ action call and `live-reactive` write the client sends, and before nothing
722
+ else: not server-side assignments, the defaults applied at subscribe, or
723
+ `stream_from` callbacks. `current_dispatch` says what is being dispatched
724
+ (`kind`, `name`, `params` or `value`). `throw :abort` skips the message and
725
+ still answers it, so the loading state clears; an error raised goes to
726
+ `rescue_from` like one raised by an action. Callbacks are inherited, so an
727
+ `ApplicationComponent` can declare one for every component (gem).
728
+ - **`live_cable_identity_tag`, so a sign-in or sign-out in a tab moves its
729
+ socket on.** A socket is identified once, at its handshake, and Turbo keeps
730
+ it open across sign-in, sign-out and impersonation, all ordinary form
731
+ submissions; after user A signed out and user B signed in, every component
732
+ in the tab kept acting as A. The helper renders a meta tag carrying a keyed
733
+ digest of whatever the application identifies sockets by; when a Turbo
734
+ visit brings a different one, the client closes the socket and opens a new
735
+ one before the new page's components subscribe, and they come back as the
736
+ new session. Other tabs, and access revoked by someone else, are the
737
+ application's to handle with ActionCable's
738
+ `remote_connections.where(...).disconnect`; the architecture guide's
739
+ *Sign-in, Sign-out and Revocation* shows the Devise wiring.
740
+
741
+ ### Changed
742
+
743
+ - Framework warnings - a component rendered without a `.live.erb` template, a
744
+ missing `app/live` directory - go through the Rails logger once per process,
745
+ instead of `Kernel#warn` to stderr on every render (gem).
746
+ - RuboCop now fails CI.
747
+
9
748
  ## 0.3.0 - 2026-09-26
10
749
 
11
750
  ### Upgrading from 0.2