Comments (11)
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:
VM1314 frame-modern.4decb80c.js:1 Uncaught TypeError: Cannot read property 'document' of null
at s (VM1314 frame-modern.4decb80c.js:1)
at Object.read (VM1314 frame-modern.4decb80c.js:1)
at VM1314 frame-modern.4decb80c.js:1
at session_Session.createOrUpdateUser (VM1314 frame-modern.4decb80c.js:1)
at app_App.createOrUpdateUser (VM1314 frame-modern.4decb80c.js:1)
at Object.update (VM1314 frame-modern.4decb80c.js:1)
at VM1314 frame-modern.4decb80c.js:1
at <anonymous>:3:213
at <anonymous>:3:650
at replaceElementWithElement (turbo.es2017-esm.js:1476)
It looks like it's coming from Turbo, but the Intercom widget disappears as well. Is anyone else seeing this?
from intercom-rails.
The Intercom widget listens to turbo:load
, turbo:visit
, and turbo:before-cache
events.
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.
from intercom-rails.
Still an issue after two years. Any update from maintainers?
from intercom-rails.
This seems to have been fixed. The Intercom script now includes Turbo events:
And we've stopped seeing this error at some point in the last few days.
from intercom-rails.
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.
from intercom-rails.
@Petercopter, that error is coming from the Intercom widget. For 422 responses, I see an error coming from frame.134abfc8.js
. I'll probably open a ticket for them.
from intercom-rails.
APP ID: 15540
User/Lead (who reported issue): 5622a0411cf1a9784902c642
Can Impersonate?: No
Conversation with Customer: https://intercomrades.intercom.com/a/apps/tx2p130c/inbox/inbox/4697146/conversations/40612403733
from intercom-rails.
@mrhead thanks for all the details! Do you know if this was ever resolved?
from intercom-rails.
@summera It looks like this was never fixed. When I remove our workaround, the Intercom widget fails on unsuccessful form submission.
from intercom-rails.
@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 turbo:load
event? Maybe the same code could be executed in your workaround instead of firing off Turbo events?
from intercom-rails.
I can confirm that this is still an issue.
from intercom-rails.
Related Issues (20)
- How should I set `unsubscribed_from_emails`?
- Messenger is not visible in Rails 6.0rc2 HOT 6
- Some action in Muster failing for ASGs with more than 100 hosts HOT 1
- Intercom preventing some users from signing in or signing up HOT 2
- How do I arbitrarily show/hide the intercom widget with js? HOT 3
- Invalid markup (script tags should be in head)
- Intercom, Sentry, and Turbolinks don't play nicely together HOT 5
- Turn off tracking for individual users HOT 1
- Shutdown not working properly
- api_base config key unsupported HOT 2
- Is there a way to listen for outgoing message events on the client-side? HOT 2
- Ability to hide chat for selected users/accounts HOT 1
- Error: invalid filter name app_id HOT 3
- Second user session (SuperAdmin User) being tracked by Intercom
- CDATA in intercom_script_tag results in the csp_sha256 mismatch and a failing CSP HOT 3
- Add At-risk-of-Breach categorisation
- Defer loading
- Firefox is triggering NS_ERROR_NOT_INITIALIZED causing intercom to stop working between page turbo page loads
- The Intercom launcher is not loading with Turbo HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from intercom-rails.