slim-template / slim

Slim is a template language whose goal is to reduce the syntax to the essential parts without becoming cryptic.

Home Page:https://slim-template.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rails 7.1 breaks slim partial block rendering when the partial is empty

rbclark opened this issue · comments

It seems there was a change in Rails 7.1 that broke how block rendering works with slim.

Description

After upgrading to Rails 7.1 I noticed that my page was double rendering itself in some spots. For some reason in Rails 7.1 the following code causes the parent partial to be passed to the block instead of the actual expected block:

application.html.slim

doctype html
html
  head
  body
    div = "Some Text"
    = turbo_frame_tag :flashes do
      = render "shared/flashes"

shared/_flashes.html.slim

= flash[:notice] || flash[:alert]

turbo-rails/app/helpers/turbo/frames_helper.rb
https://github.com/hotwired/turbo-rails/blob/18097993736df0af3a361a253a5b920a3b5e3363/app/helpers/turbo/frames_helper.rb#L38-L43

Expected Behavior

This should render "Some Text" a single time whether or not the flash is present.

Actual Behavior

When no flash is present this for some reason re-renders the whole parent page again.

No flash present
(You can see in the screenshot below that the "Some Text" was rendered inside the turbo_frame_tag even though it was supposed to only be rendering "shared/flashes")
Screenshot 2023-10-10 at 11 49 39 AM

Flash present
(Things work as expected)
Screenshot 2023-10-10 at 11 51 10 AM

Additional Resources

rails/rails#47194 - I did a git bisect on rails and discovered that this is the PR with the commit causing the issue.

Final thoughts

It looks like this refactor broke some things in haml as well rails/rails#47443

Likely fix in Rails coming: rails/rails#49612

This was only tested w/ haml, so it will need to be tested w/ slim

I merged the Rails fix and backported to 7-1-stable. Please let me know if somehow that doesn't fix the bug. It should be released as part of rails 7.1.2.

Fixed in Rails 7.1.2