Modern Front-End Development for Rails: Can't get TURBO_STREAM format in some cases

This isn’t directly about the book contents so maybe not the right forum…but in some of the code apps (e.g. turbo/06) it sends a TURBO_STREAM request and in others (e.g. turbo/01) it’s always HTML, even from a link inside a turbo_frame.

No doubt it is something in my environment. I’ve gone through diffs painstakingly setting every yarn package version etc. to match the working app where different. But I can’t get a TURBO_STREAM in a new rails project or in some of the sample code apps.

I know there are a million combination of versions of everything so this is an impossible question to answer, but any suggestions?! I’ve tried reinstalling everything a million times. The new version of the book is great, I’d love to put it into use but guess I’ll have to wait a few months and try again.

Hi – all the code apps should work (unless there’s a bug I haven’t seen), and there shouldn’t be anything between turbo/01 and turbo/06 that would break the app. (I guess it’s possible that turbo/01 isn’t fully set up, does turbo/02 work?) I’m curious what links are working and what links are breaking.

Hi, you’re right turbo/02 does work.
I took a fresh copy of the code. turbo/01 sends HTML rather than TURBO_STREAM, so maybe it’s just not set up at that point.

Thanks that reduced the variables, it’s the turbo-rails gem version that breaks for me from v0.5.4 It won’t send a TURBO_STREAM (same on latest v0.5.9).

Looking forward to continuing the book with the older turbo-rails gem for now, thanks.

UPDATE: If I run yarn upgrade it breaks again, even with turbo-rails gem v0.5.3
But if I then paste the older yarn.lock lines back in for turbo-rails and turbo and run webpacker:install, it works again. Even though the version @hotwired/turbo-rails@^7.0.0-beta.2 is the same in both cases, yarn upgrade changes the t.r. version referenced below from beta.2 to beta.5 (and the turbo dependency from beta.1 to beta.4).

Pasting back to beta.2 and beta.1 for turbo-rails and turbo resp. fixes it (ie TURBO_STREAM requests).
So reverting to the red below fixes it. I’ve no idea if that’s significant!

Unrelated but it seems the target type declaration is no longer needed (happy days): Uncaught (in promise) TypeError: setting getter-only property "elementToHideTarget"
Removing elementToHideTarget: HTMLElement fixes it

1 Like

I wonder if this is related to Restrict Accept: turbo-stream to Form Submissions by seanpdoyle · Pull Request #52 · hotwired/turbo · GitHub and there is some difference in the earlier code that doesn’t quite match the later turbo betas.

I think the TypeError may be related to TypeScript and babel settings, I think Sam is working on a fix where you won’t have to enter the target declarations, but I don’t think it’s been merged yet.

Thanks for posting @alanq … it’s not working for me either. I was excited to see the magic header in my Chrome Dev Tools Network tab, but it doesn’t appear. The Rails log has “Processing … as HTML” not “as TURBO_STREAM”.

I actually have turbo-rails 0.5.2 and I have tried both the 2/1 beta and the 5/4 beta in the package.json and yarn.lock and I can’t get it to work either way.

I’m in that section of the code right now as I do the final text review on the book. I may post a zip file here for you to test out if I can’t see the problem as I go through the examples.

I hit the same issue in another app that’s using asset pipeline instead of webpacker. After downgrading turbo-rails to 0.5.3 from latest 0.5.9, TURBO_STREAM appears in the console where before it was HTML.