-
Notifications
You must be signed in to change notification settings - Fork 415
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
Final newline is rendered #913
Comments
Thanks for opening this! We should definitely support this case. Any interest in opening a pull request to fix this issue? Even if the PR only includes a failing test that would help us resolve the issue sooner. |
Yeah, I'd be happy to do that. I'll get on it right away ✨ |
Alright, done 👍 |
Raised rails/rails#42201, because this issue's really more in the remit of Action View. Whether it gets fixed by proxy of a change to Rails is something we can't yet be sure of, so I'd leave this open. The failing test can probably also be taken out or adapted to document the fix if a change to Rails will fix it. |
That PR got merged, so I'll raise another one here to change those tests back to their original form. If the change to the ERB renderer fixed the issue here, then there shouldn't be a need for further work. Otherwise, I'll consider adding a config option to ViewComponent for this. |
|
I'm updating the tests in #958 - can I get some advice on how best to do this (if at all just yet) given that the functionality is only in edge Rails? |
Just encountered this again - if def render_in(view_context)
output = super
return output unless ActionView::Template::Handlers::ERB.strip_trailing_newlines
output.chomp
end |
Reduced test case: https://github.com/boardfish/view_component-bug
Steps to reproduce
Render a component that uses a HTML element with
display: inline
by default, e.g.span
ora
, inline.Expected behavior
There should be no trailing whitespace. i.e. I should be able to do this:
and receive:
as opposed to:
Actual behavior
It seems as though the final newline of the template file is rendered, even though this usually indicates the end of a file. This is interpreted by browsers to mean whitespace.
The newline preceding the comma is rendered from the component template. The following whitespace is part of the view template.
System configuration
Rails version: 6.1.3.2
Ruby version: 2.7.3
Gem version: 2.31.1
The text was updated successfully, but these errors were encountered: