Is there a way to make lazy Turbo Frames accept `text/vnd.turbo-stream.html`?

I have a lazy Turbo Frame, roughly like this:

<turbo-frame id="this-frame" src="/my/cool/url" loading="lazy" />

When that frame is visible, a request is made to the server. Among other things, the request headers contain:

Accept: text/html, application/xhtml+xml
Turbo-Frame: this-frame

Right now, my code looks for that Turbo-Frame header to decide if it should return a focused amount of data via a Turbo Stream or the whole page as straight HTML.

This works, but it feels weird that this part of my app looks for the Turbo-Frame header while other endpoints look for the Accept header to contain text/vnd.turbo-stream.html. Is there a way to add that content type to the request made by the lazy frame request?

2 Likes

Hello, I feel your pain about that. This issue explain a little bit why this happens, turbo-frame tage with 'src' attribute not adding proper mimetype to fetch request · Issue #1013 · hotwired/turbo · GitHub.

But I agree with you, maybe we have some way to make a lazy loading request easly that calls a turbo-stream request.

My use case for this is like lazy loading one tab inside a page with multiple tabs (And the user can enter each tab by query params). If the user type this route by hand they will receive an strange HTML response instead a 404