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

Fix unwanted model retention when using class methods from Turbo::Broadcastable with locals #710

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

v-yarotsky
Copy link

Consider the following model:

class MyModel < ApplicationRecord
  broadcasts locals: { something_static: true }
end

When broadcasting for the first time without this fix, Broadcastable does something like:

{ something_static }.reverse_merge!(my_model: #<MyModel: id=1>)

On the second broadcast for another model instance, the reverse merge will be a no-op, because the first model is already in the Hash!

Switching to a non-destructive reverse_merge resolves the issue.

…oadcastable` with locals

Consider the following model:

```ruby
class MyModel < ApplicationRecord
  broadcasts locals: { something_static: true }
end
```

When broadcasting for the first time without this fix, Broadcastable
does something like:

```
{ something_static }.reverse_merge!(my_model: #<MyModel: id=1>)
```

On the second broadcast for another model instance, the reverse merge
will be a no-op, because the first model is already in the Hash!

Switching to a non-destructive `reverse_merge` resolves the issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant