How to troubleshoot Turbo issues?

Hello all! I’m using Rails with turbo-rails gem v1.4.0 and importmaps.

I recently updated Rails from 7.05 to 7.1.2 and discovered that turbo drive isn’t exactly working anymore. Trying to log in, in Dev Tools Network tab, you can see the request complete successfully, redirect to root, you can see root requested, but the page does not update, the location in the browser does not update.

In general, I’m having a hard time figuring out to debug turbo drive/stream/frame issues when things aren’t working how I expect them to. I’d love some pointers here… where should I put debuggers, what should I look for?

Thanks in advance :pray:

OK I figured it out and it had nothing to do with upgrading Rails :sweat_smile:

Recently I had also added a respond_to block in the target controller action with a format.turbo_stream for a different use case—it’s a search page, and the search uses a GET form so that search results pages will be linkable.

I added the following to my application.js file to debug:

const events = [
  "turbo:fetch-request-error",
  "turbo:frame-missing",
  "turbo:frame-load",
  "turbo:frame-render",
  "turbo:before-frame-render",
  "turbo:load",
  "turbo:render",
  "turbo:before-stream-render",
  "turbo:before-render",
  "turbo:before-cache",
  "turbo:submit-end",
  "turbo:before-fetch-response",
  "turbo:before-fetch-request",
  "turbo:submit-start",
  "turbo:visit",
  "turbo:before-visit",
  "turbo:click"
]

events.forEach(e => {
  addEventListener(e, () => {
    console.log(e);
  });
});

So in my case, I saw a bunch of events, ending in turbo:before-stream-render (of course there’s no after stream render event*, but nonetheless) this was enough to get me on the right path.

Now in my controller I’ve added a before_action :set_format that sets request.format = :html unless ... checking the referrer for the appropriate path.

*I’ve actually added a custom after-stream-render event but forgot to log it here :woozy_face: