Socket
Socket
Sign inDemoInstall

@hotwired/turbo-rails

Package Overview
Dependencies
Maintainers
4
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hotwired/turbo-rails - npm Package Compare versions

Comparing version 8.0.9 to 8.0.10

10

app/javascript/turbo/cable_stream_source_element.js

@@ -6,2 +6,4 @@ import { connectStreamSource, disconnectStreamSource } from "@hotwired/turbo"

class TurboCableStreamSourceElement extends HTMLElement {
static observedAttributes = ["channel", "signed-stream-name"]
async connectedCallback() {

@@ -19,4 +21,12 @@ connectStreamSource(this)

if (this.subscription) this.subscription.unsubscribe()
this.subscriptionDisconnected()
}
attributeChangedCallback() {
if (this.subscription) {
this.disconnectedCallback()
this.connectedCallback()
}
}
dispatchMessageEvent(data) {

@@ -23,0 +33,0 @@ const event = new MessageEvent("message", { data })

2

package.json
{
"name": "@hotwired/turbo-rails",
"version": "8.0.9",
"version": "8.0.10",
"description": "The speed of a single-page web application without having to write any JavaScript",

@@ -5,0 +5,0 @@ "module": "app/javascript/turbo/index.js",

@@ -103,2 +103,60 @@ # <img src="assets/logo.png?sanitize=true" width="24" height="24" alt="Turbo"> Turbo

### Testing Turbo Stream Broadcasts
Receiving server-generated Turbo Broadcasts requires a connected Web Socket.
Views that render `<turbo-cable-stream-source>` elements with the
`#turbo_stream_from` view helper incur a slight delay before they're ready to
receive broadcasts. In System Tests, that delay can disrupt Capybara's built-in
synchronization mechanisms that wait for or assert on content that's broadcast
over Web Sockets. For example, consider a test that navigates to a page and then
immediately asserts that broadcast content is present:
```ruby
test "renders broadcasted Messages" do
message = Message.new content: "Hello, from Action Cable"
visit "/"
click_link "All Messages"
message.save! # execute server-side code to broadcast a Message
assert_text message.content
end
```
If the call to `Message#save!` executes quickly enough, it might beat-out any
`<turbo-cable-stream-source>` elements rendered by the call to `click_link "All
Messages"`.
To wait for any disconnected `<turbo-cable-stream-source>` elements to connect,
call [`#connect_turbo_cable_stream_sources`](turbo-rails/blob/wait-for-cable-stream-sourceshttps://github.com/hotwired/turbo-rails/blob/main/lib/turbo/system_test_helper.rb):
```diff
test "renders broadcasted Messages" do
message = Message.new content: "Hello, from Action Cable"
visit "/"
click_link "All Messages"
+ connect_turbo_cable_stream_sources
message.save! # execute server-side code to broadcast a Message
assert_text message.content
end
```
By default, calls to [`#visit`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara/Session:visit) will wait for all `<turbo-cable-stream-source>` elements to connect. You can control this by modifying the `config.turbo.test_connect_after_actions`. For example, to wait after calls to [`#click_link`](https://rubydoc.info/github/teamcapybara/capybara/master/Capybara/Node/Actions:click_link), add the following to `config/environments/test.rb`:
```ruby
# config/environments/test.rb
config.turbo.test_connect_after_actions << :click_link
```
To disable automatic connecting, set the configuration to `[]`:
```ruby
# config/environments/test.rb
config.turbo.test_connect_after_actions = []
```
[See documentation](https://turbo.hotwired.dev/handbook/streams).

@@ -144,2 +202,3 @@

- [Turbo Broadcastable Test Helper](https://rubydoc.info/github/hotwired/turbo-rails/main/Turbo/Broadcastable/TestHelper)
- [Turbo System Test Helper](https://rubydoc.info/github/hotwired/turbo-rails/main/Turbo/SystemTestHelper)

@@ -146,0 +205,0 @@ ## Compatibility with Rails UJS

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc