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

Why are WS/SEE not being closed after turbo-stream-source is gone? #969

Closed
guillermo opened this issue Sep 5, 2023 · 2 comments · Fixed by #970
Closed

Why are WS/SEE not being closed after turbo-stream-source is gone? #969

guillermo opened this issue Sep 5, 2023 · 2 comments · Fixed by #970

Comments

@guillermo
Copy link

I am using Hotwired/Turbo in a go application.
On one specific page, I want to update several partials from the server asynchronously as they arrive to the server through external apis (openAI in this case).

I used this on my views:

<turbo-frame id="articles_list">
...
<turbo-stream-source src="/repurpose/{{ .ID }}/"></turbo-stream>
...
</turbo-frame>

It normally works as expected, and I can update the page nicely.

But the moment that I navigate to another page (so the turbo-stream-source gets unloaded), the ws/see connection is ignored but not closed.

if (this.streamSource) {
disconnectStreamSource(this.streamSource)
}

This creates unlimited connections until I reach the browsers max, and can't navigate anymore.

I fixed it locally by modifying the source and manually closing the connection with this.streamSource.close();:

class StreamSourceElement extends HTMLElement {
...
    disconnectedCallback() {
        if (this.streamSource) {
            disconnectStreamSource(this.streamSource);
            this.streamSource.close();
        }
    }
...
}

The change seems obvious for my use case, but makes me wonder if I am using hotwire turbo as design.

Are only fixed constant connections like /cable in rails the only recommended use case?

seanpdoyle added a commit to seanpdoyle/turbo that referenced this issue Sep 5, 2023
Closes [hotwired#969][]

When a `<turbo-stream-source>` element is removed, close the connection
that is created during connection.

[hotwired#969]: hotwired#969
@seanpdoyle
Copy link
Contributor

Thank you for opening this issue, and for sharing your solution.

I've opened #970 to resolve it.

shiftyp pushed a commit to shiftyp/ts-turbo that referenced this issue Sep 9, 2023
Closes [hotwired#969][]

When a `<turbo-stream-source>` element is removed, close the connection
that is created during connection.

[hotwired#969]: hotwired#969
shiftyp pushed a commit to shiftyp/ts-turbo that referenced this issue Sep 9, 2023
Closes [hotwired#969][]

When a `<turbo-stream-source>` element is removed, close the connection
that is created during connection.

[hotwired#969]: hotwired#969
shiftyp pushed a commit to shiftyp/ts-turbo that referenced this issue Sep 9, 2023
Closes [hotwired#969][]

When a `<turbo-stream-source>` element is removed, close the connection
that is created during connection.

[hotwired#969]: hotwired#969
shiftyp pushed a commit to shiftyp/ts-turbo that referenced this issue Sep 9, 2023
Closes [hotwired#969][]

When a `<turbo-stream-source>` element is removed, close the connection
that is created during connection.

[hotwired#969]: hotwired#969
shiftyp pushed a commit to shiftyp/ts-turbo that referenced this issue Sep 9, 2023
Closes [hotwired#969][]

When a `<turbo-stream-source>` element is removed, close the connection
that is created during connection.

[hotwired#969]: hotwired#969
shiftyp pushed a commit to shiftyp/ts-turbo that referenced this issue Sep 10, 2023
Closes [hotwired#969][]

When a `<turbo-stream-source>` element is removed, close the connection
that is created during connection.

[hotwired#969]: hotwired#969
shiftyp pushed a commit to shiftyp/ts-turbo that referenced this issue Sep 10, 2023
Closes [hotwired#969][]

When a `<turbo-stream-source>` element is removed, close the connection
that is created during connection.

[hotwired#969]: hotwired#969
shiftyp pushed a commit to shiftyp/ts-turbo that referenced this issue Sep 10, 2023
Closes [hotwired#969][]

When a `<turbo-stream-source>` element is removed, close the connection
that is created during connection.

[hotwired#969]: hotwired#969
shiftyp pushed a commit to shiftyp/ts-turbo that referenced this issue Sep 10, 2023
Closes [hotwired#969][]

When a `<turbo-stream-source>` element is removed, close the connection
that is created during connection.

[hotwired#969]: hotwired#969
seanpdoyle added a commit to seanpdoyle/turbo that referenced this issue Sep 11, 2023
Closes [hotwired#969][]

When a `<turbo-stream-source>` element is removed, close the connection
that is created during connection.

[hotwired#969]: hotwired#969
@kwhandy
Copy link

kwhandy commented Feb 8, 2024

is this issue causing response on network tab which keep receives {"type":"ping","message":Id}, even after we move to another page which doesn't have turbo-stream-source tag in it? if yes, it's still happening right now cuz i just upgrade mine to v8 @seanpdoyle @guillermo

rails 7.1.3
turbo 8.0.0
turbo-rails 2.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants