-
Notifications
You must be signed in to change notification settings - Fork 107
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
Compatibility with hotwired/turbo-rails #336
Comments
Oh that's great! Thanks letting me know. Intercom support were helpful and receptive but I didn't expect to see it incorporated this quickly. |
I'm doing the same thing, migrating to Hotwire from Turbolinks. For forms that fail validation, we used to just render with a 200 OK. But now, we need to render with a 422 Unprocessable Entity. hotwired/turbo-rails#34 (comment) When I get the 422, I get this error:
It looks like it's coming from Turbo, but the Intercom widget disappears as well. Is anyone else seeing this? |
@Petercopter, that error is coming from the Intercom widget. For 422 responses, I see an error coming from |
The Intercom widget listens to Turbo doesn't fire any of these events during unsuccessful form submission, so the widget can't prepare itself for the DOM change. I've already opened a ticket for Intercom so they can improve it, but in the meantime I've came up with the following workaround: document.addEventListener("turbo:submit-end", (event) => {
window.turboFormSubmissionFailed = !event.detail.success
if(window.turboFormSubmissionFailed) {
document.dispatchEvent(new Event('turbo:visit'))
document.dispatchEvent(new Event('turbo:before-cache'))
}
})
document.addEventListener("turbo:render", () => {
if(window.turboFormSubmissionFailed) {
document.dispatchEvent(new Event('turbo:load'))
window.turboFormSubmissionFailed = false
}
}) This code emulates the page visit flow after unsuccessful form submission, and it fixes issues with the widget. |
APP ID: 15540 |
@mrhead thanks for all the details! Do you know if this was ever resolved? |
@summera It looks like this was never fixed. When I remove our workaround, the Intercom widget fails on unsuccessful form submission. |
@mrhead thanks for checking! Apparently this is a deeper issue that others have brought up in the Turbo repo:
I wonder if there's a way to gracefully shut down and restart the Intercom widget without simulating the Turbo events. Any idea what the Intercom JS script is doing when it receives the |
Still an issue after two years. Any update from maintainers? |
I can confirm that this is still an issue. |
I started migrating a project from Turbolinks to the Turbo project and hit some issues. I have a workaround which might be useful to include in the documentation, or at least have here for others who encounter the same problem. Let me know if it would be helpful to PR somewhere.
Turbo feels like a drop-in replacement but it doesn't profess to being backwards compatible as DHH outlines: hotwired/turbo-rails#67
Although Turbo follows the same patterns as Turbolinks, and has the same events, i.e.
before-cache
,visit
,load
etc. they are now namespaced underturbo
instead ofturbolinks
, soturbolinks:load
is nowturbo:load
.The IntercomJS client that gets loaded from Intercom has a bunch of Turbolinks event listeners, as you can see if you view the file and ctrl-f for Turbolinks. Due to the new names these event listeners are ignored and Intercom throws the following error when navigating via Turbo.
I've messaged Intercom support and asked them to consider including the new event names alongside the current ones. In the meantime I've found the following workaround:
Version info
Expected behavior
Intercom works when using Turbolinks to navigate
Actual behavior
Intercom JS throws an error
Steps to reproduce
Logs
The text was updated successfully, but these errors were encountered: