Add support to replace the turbo_frame contents #145
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We've identified an area for improvement in the current turbo-frame command handling.
Current Behaviour
Currently when a command is initiated within a turbo-frame and no turbo stream is available, the entire HTML is recreated on the server and sent back to the client. The client then utilized the Append strategy, appending the content to the current document.
Difference between Command and TurboLinks behavior
In contrast, clicking a link within a turbo frame only replaces the contents of the frame with the corresponding frame content from the returned HTML. You can read more about this behavior here.
Benefits of the Turbo Links Behavior
The turbo links behavior is particularly beneficial in scenarios where the controller and the HTML contain extensive logic. Implementing parts of this logic within turbo streams can be cumbersome, requiring significant effort and increasing maintenance overhead. By adopting the FrameReplace strategy, we alleviate the need to replicate complex logic in turbo streams, simplifying the development process and reducing potential maintenance challenges.
To enhance consistency and improve user experience, we've introduced a new strategy called FrameReplace in this PR. This strategy morphs the current content of the turbo frame with the returned content of the turbo frame, mimicking the behavior of turbo links.
Key Points of the FrameReplace Strategy:
We believe this update will significantly enhance the functionality and user experience of turbo frames.