Code Monkey home page Code Monkey logo

Comments (11)

Petercopter avatar Petercopter commented on September 13, 2024 2

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.

mrhead avatar mrhead commented on September 13, 2024 1

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.

hirowatari avatar hirowatari commented on September 13, 2024 1

Still an issue after two years. Any update from maintainers?

from intercom-rails.

ghiculescu avatar ghiculescu commented on September 13, 2024

This seems to have been fixed. The Intercom script now includes Turbo events:

image

And we've stopped seeing this error at some point in the last few days.

from intercom-rails.

hcurotta avatar hcurotta commented on September 13, 2024

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.

mrhead avatar mrhead commented on September 13, 2024

@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.

tomdevery avatar tomdevery commented on September 13, 2024

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.

summera avatar summera commented on September 13, 2024

@mrhead thanks for all the details! Do you know if this was ever resolved?

from intercom-rails.

mrhead avatar mrhead commented on September 13, 2024

@summera It looks like this was never fixed. When I remove our workaround, the Intercom widget fails on unsuccessful form submission.

from intercom-rails.

summera avatar summera commented on September 13, 2024

@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.

arutinn avatar arutinn commented on September 13, 2024

I can confirm that this is still an issue.

from intercom-rails.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.