Skip to content

[Turbo] Render TurboStream (wip) #2122

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

Closed
wants to merge 1 commit into from

Conversation

DRaichev
Copy link
Contributor

@DRaichev DRaichev commented Sep 2, 2024

Q A
Bug fix? no
New feature? yes
Issues Fix #2068
License MIT

This is a WIP to aid in further discussions of the RFC implementation

@smnandre As discussed in #2068 I have opened a PR with some rough outline of the implementation

It is far from ready, but I think it is a good start. I can continue to work on this, but I will need some direction.
I understand now what you meant earlier - the bundle is an independent component not tied to the symfony framework's AbstractController, nor HttpFoundation nor even Twig

So I think my initial concept should be split into 2 parts - one is the abstract implementation of rendering streams, or rather wrapping a view in a turbo stream, and the other part should be specific to the full-fat symfony framework and it will build on top of the first to provide an easy way to go from a bunch of turbo streams to a HttpFoundation\Response with the correct content type, etc.

@carsonbot carsonbot added Feature New Feature Status: Needs Review Needs to be reviewed labels Sep 2, 2024
@smnandre
Copy link
Member

smnandre commented Sep 2, 2024

Nice, thank you!

Could you change the PR status to DRAF, that way everyone knows it's a work-in-progress ?

I think the best now would be some examples of what it would allow (like concrete scenarios / usages, showing the final goal and where the DX / entrypoints would be used/called)

I'll have a better look later in the week :)

@smnandre smnandre added the Turbo label Sep 2, 2024
@smnandre smnandre changed the title WIP #2068 [Turbo] Render TurboStream (wip) Sep 2, 2024
@DRaichev DRaichev marked this pull request as draft September 2, 2024 19:56
@javiereguiluz
Copy link
Member

Question: is this idea something we still want to do ... or is it enough with the changes that we merged in #2227 and #2196?

@DRaichev
Copy link
Contributor Author

DRaichev commented Oct 23, 2024

Question: is this idea something we still want to do ... or is it enough with the changes that we merged in #2227 and #2196?

I think the referenced changes cover 90% of what I wanted to achieve.
In fact it is very similar to what I had as a WIP implementation at my company.

In terms of UX what's missing/different is the ability to render a twig file.
With those new changes you can use the TurboResponse and pass it streams, but they can only get rendered html.

What I'd like to do is pass a .twig file along with the required params, and the turbo action and it would render the twig to html, wrap that in a turbo stream and then wrap the stream(s) in the TurboResponse.

What I did in my internal WIP is make a render function that uses the regular render and takes the content of that and adds it. I can do the same now, but it is kind of ugly.
I am using the full symfony framework and I would like to use the abstract controller's methods, but they are private and on top of that some of the logic is split in a way that makes it inconvenient to reuse.

As an intermediate step I will use the improvements added in #2196 and #2227.
In order to achieve my vision some code would need to change in the framework-bundle AbstractController which I think is outside of the scope/control of this community, but if you have any advice, or think it is possible I'd appreciate it. If not I think this issue & PR can be closed.

P.S.

One more thing - the current implementation also has no generic action (only the predefined turbo actions) and what's more the class is marked as final, which does not allow me to add support for more actions. I think the wrap function should be public or have a public function "custom" that exposes the functionality.

I really like this library: https://github.com/marcoroth/turbo_power
It adds additional simple actions for example I use set/delete attributes to control enable/disable UI elements

Maybe this should be added, while my other idea can be ditched as it is too dependent on the framework bundle / specific renderer implementation

@DRaichev
Copy link
Contributor Author

Since this overlaps some functionality implemented in #2196, the difference is moved to another PR #2298

@DRaichev DRaichev closed this Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New Feature Status: Needs Review Needs to be reviewed Turbo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Idea] [Turbo Streams] [ux-turbo] Render view as Turbo Stream
4 participants