Skip to content
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 Drive: Stimulus doesn't disconnect/connect after redirection to same URL #775

Open
elsurudo opened this issue Jun 15, 2024 · 3 comments

Comments

@elsurudo
Copy link

Hello,

Basically as the title says: after a Turbo form submission, if I redirect to the same page then the Stimulus lifecycle events don't fire. Any new Stimulus controllers that are in the redirected-to page don't have their connect methods called, and hence they don't initialize.

Is it a bug, or expected behaviour? And is there a workaround?

@tpaulshippy
Copy link

tpaulshippy commented Jun 15, 2024

Reminds me of
hotwired/turbo#1083 (comment)

Is morphing enabled?

@elsurudo
Copy link
Author

Morphing is indeed enabled, and it does seem related to that thread.

The solutions in that thread didn't work for me, although I was able to get around the issue by adding a "dummy" param (for example success=true) to the path I redirect to to force the disconnect/reconnect. It's a bit ugly, but at least works for now.

Still, this was pretty surprising behaviour, so it would be nice to have a better, "sanctioned" solution to this.

@elsurudo
Copy link
Author

This also impacts the following (quite common I imagine?) use-case:

  1. Submit form (using Turbo) that happens to have a Stimulus controller on it
  2. There is a form error, hence we render 422 unprocessable entity
  3. Errors are shown, but Stimulus controllers on the form are not loaded (form is broken)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants