-
Notifications
You must be signed in to change notification settings - Fork 429
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
Turbo stream source #415
Turbo stream source #415
Conversation
Add a `<form>` element to the `src/tests/fixtures/stream.html` file so that tests can exercise receiving `<turbo-stream>` elements asynchronously over an `EventSource` instance that polls for Server-sent Events. Extend the `src/tests/server.ts` to account for the `Accept: text/event-stream` requests that are made by browsers via the `new EventSource(...)` instance.
Closes hotwired#413 The `<turbo-stream-source>` element accepts a `[src]` attribute, and uses that to connect Turbo to poll for streams published on the server side. When the element is connected to the document, the stream source is connected. When the element is disconnected, the stream is disconnected. When declared with an `ws://` or `wss://` URL, the underlying Stream Source will be a `WebSocket` instance. Otherwise, the connection is through an `EventSource`. Since the document's `<head>` is persistent across navigations, the `<turbo-stream-source>` is meant to be mounted within the `<body>` element. Typical full page navigations driven by Turbo will result in the `<body>` being discarded and replaced with the resulting document. It's the server's responsibility to ensure that the element is present on each page that requires streaming.
e015320
to
feb52fa
Compare
Great! I am not sure about the head / body assertion being made, nor the assumption about full page updates by Turbo (I certainly would never do that). |
This is great, @seanpdoyle, we just need to pair it up with the existing tag that was put in turbo-rails. Or rather, make turbo-rails use this more generic approach directly. |
Unless I'm misunderstanding some fundamentals about the Action Cable source, that element isn't declared with an I understand the idea to unify the two to re-use the same mechanics or classes, but I don't see a path forward. |
Ah, yes, fair enough. This is mostly then for use outside of Rails. Which is fine. |
There's a few lint errors, if you want to sort. |
Document the `<turbo-stream-source>` element introduced in [hotwired/turbo#415][]. [hotwired/turbo#415]: hotwired/turbo#415
* main: Drive Browser tests with `playwright` (hotwired#609) Allow Turbo Streams w/ GET via `data-turbo-stream` (hotwired#612) Only update history when Turbo visit is renderable (hotwired#601) Support development ChromeDriver version overrides (hotwired#606) Turbo stream source (hotwired#415) Expose Frame load state via `[complete]` attribute (hotwired#487)
* main: Allow frames to scroll smoothly into view (hotwired#607) Export Type declarations for `turbo:` events (hotwired#452) Add .php as a valid isHTML extension (hotwired#629) Add original click event to 'turbo:click' details (hotwired#611) Drive Browser tests with `playwright` (hotwired#609) Allow Turbo Streams w/ GET via `data-turbo-stream` (hotwired#612) Only update history when Turbo visit is renderable (hotwired#601) Support development ChromeDriver version overrides (hotwired#606) Turbo stream source (hotwired#415) Expose Frame load state via `[complete]` attribute (hotwired#487) fix(ie/edge): form.method='delete', raises Invalid argument. (hotwired#586) Do not declare global types/constants (hotwired#524) Defensively create custom turbo elements (hotwired#483) Use `replaceChildren` in StreamActions.update (hotwired#534)
Improve test coverage for streams over SSE
Add a
<form>
element to thesrc/tests/fixtures/stream.html
file sothat tests can exercise receiving
<turbo-stream>
elementsasynchronously over an
EventSource
instance that polls for Server-sentEvents.
Extend the
src/tests/server.ts
to account for theAccept: text/event-stream
requests that are made by browsers via thenew EventSource(...)
instance.Introduce
<turbo-stream-source>
Closes #413
The
<turbo-stream-source>
element accepts a[src]
attribute, anduses that to connect Turbo to poll for streams published on the server
side.
When the element is connected to the document, the stream source is
connected. When the element is disconnected, the stream is disconnected.
When declared with an
ws://
orwss://
URL, the underlying StreamSource will be a
WebSocket
instance. Otherwise, the connection isthrough an
EventSource
.Since the document's
<head>
is persistent across navigations, the<turbo-stream-source>
is meant to be mounted within the<body>
element.
Typical full page navigations driven by Turbo will result in the
<body>
being discarded and replaced with the resulting document. It'sthe server's responsibility to ensure that the element is present on
each page that requires streaming.