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

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

Closed
rbclark opened this issue Oct 10, 2023 · 3 comments
Closed

Comments

@rbclark
Copy link

rbclark commented Oct 10, 2023

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

@aaronjensen
Copy link

Likely fix in Rails coming: rails/rails#49612

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

@byroot
Copy link

byroot commented Oct 13, 2023

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
Copy link
Member

minad commented Nov 11, 2023

Fixed in Rails 7.1.2

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

No branches or pull requests

4 participants