Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong Content-Type with HAML #287

Closed
jurta opened this issue Dec 21, 2021 · 7 comments
Closed

Wrong Content-Type with HAML #287

jurta opened this issue Dec 21, 2021 · 7 comments

Comments

@jurta
Copy link

jurta commented Dec 21, 2021

When views templates are written in ERB and contain a turbo_frame_tag, then for a request with the turbo-streams type, the response correctly uses the HTML content-type text/html.

But when templates are in HAML, then for a turbo-streams request, the response incorrectly uses the turbo-stream content-type text/vnd.turbo-stream.html, and the JS side fails to update the turbo frame because it expects the HTML content-type text/html.

A temporary workaround that helps to fix this problem is to force the correct HTML content-type with e.g.:

    respond_to do |format|
      format.turbo_stream { response.headers['Content-Type'] = 'text/html; charset=utf-8' } # for haml
    end
@mtomov
Copy link

mtomov commented Feb 14, 2022

Yeah! Can confirm the bug and the solution! Have you managed to find a more generic solution / patch to the issue?

Edit: Actually, this comment: #80 (comment) clarified that just adding html to the file ending would fix the issue. So name your file show.html.haml instead of show.haml

@priit
Copy link

priit commented Feb 17, 2022

I know it's against current Rails defaults about file naiming rules what was caused by flexible .erb format but let's not forget that haml is always html. Therefore semantically it's rather redudant and noisy to declare html multilpe times that haml is html where it never can be anything else. I work with view files rather often where I inspect files in tree in command line and it's rather important they are short and clear without redudant html noise.

Therefore I support any effort to keep semantically correct .haml format as well.

@Aesthetikx
Copy link

Just ran across this today during my work on a turbolinks => turbo upgrade, and we have tons of .haml files that I do not want to rename to html.haml, as that was not necessary in the past.

@Aesthetikx
Copy link

Aesthetikx commented Apr 21, 2022

It seems that as a result of e693f45e155a81b6c337b8766870b56716a05105 from 13 years ago which has made its way here, we can do the following as a 'fix' for omitting the .html in .html.haml

module Haml
  class Plugin
    def default_format
      :html
    end
  end
end

# Or,

module Hamlit
  class RailsTemplate
    def default_format
      :html
    end
  end
end

@dhh
Copy link
Member

dhh commented May 22, 2022

Seems like this is a general Rails issue. Would be happy to take a doc change to turbo-rails explaining the naming convention needs, though.

@lazylester
Copy link

the monkey patch suggested by @Aesthetikx works great on haml 5.2.2, but it doesn't look as if it's going to work on haml 6.0, as there's no plugin class to hold the monkey-patch

@lazylester
Copy link

I made a pull request for haml6 to incorporate @Aesthetikx monkey patch, haml/haml#1144

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

6 participants