I have a Turbo modal setup in my application that opens when the inner turbo frame src is set and loaded. Here’s the important bits: (using Alpine)
<div x-data="{ open: false }" @turbo:frame-load="if ($event.target.id === 'turbo-frame-modal') open = true;">
<%= turbo_frame_tag "turbo-frame-modal", target: "_top", "x-turbo-frame-src-observer":"", "@turbo:before-morph-attribute": "console.log($event.detail.attributeName, $event.detail.mutationType)" %>
</div>
I use it to load a form lets say a /edit
page. In the controller on success, I do a redirect, and Turbo updates the document via a morph operation. The markup for the new page that is being morphed has the turbo frame without a src (since it hasn’t been triggered via a link). The expected behavior is that the morph gets applied and the Modal doesn’t open because nothing gets loaded in the frame.
Whats happening is the morph gets applied removing the frames src and then immediately after, the previous src gets set on the turbo frame, triggering the modal again. I have some logs setup to trace whats going on.
From the logs the morph operation removes the src attribute, the turbo:render event gets fired after the morph is completed, and then the src gets set back to the previous url before the morph.
frame src change: null
turbo:render renderMethod=morph
frame src change: https://app.local/meetings/b8c70d46-b953-4190-b4ee-a8b335617532/edit
Listening to events, logging and tracing isn’t showing me from where this attribute change is coming from. The logs from the turbo:before-morph-attribute
event show the first changes that remove the src and nothing for when it gets set again. Really struggling to pin this down.
Wondering if anyone has any experience with this or has any ideas on how to keep it from happening. Hacking away on it I wrote some code that clones the turbo frame after the morph, removes it from the document, and then appends it back. That worked but doesn’t feel like a legit solution.