turbo_boost-commands
turbo_boost-commands copied to clipboard
Add support to replace the turbo_frame contents
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:
- Selective Activation: The FrameReplace strategy is activated only when there is no turbo stream available for the current action, ensuring backward compatibility.
- Enhanced Consistency: Commands within turbo frames now behave similarly to turbo links, providing a more intuitive and seamless user experience.
We believe this update will significantly enhance the functionality and user experience of turbo frames.