slim-template / slim

Slim is a template language whose goal is to reduce the syntax to the essential parts without becoming cryptic.
https://slim-template.github.io
MIT License
5.29k stars 500 forks source link

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

Closed rbclark closed 7 months ago

rbclark commented 8 months ago

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

https://github.com/rails/rails/pull/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 https://github.com/rails/rails/issues/47443

aaronjensen commented 8 months ago

Likely fix in Rails coming: https://github.com/rails/rails/pull/49612

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

byroot commented 8 months ago

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.

minad commented 7 months ago

Fixed in Rails 7.1.2