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

Stray text calls on method calls that render or capture for `Phlex::DeferredRender #91

Open
hangsu opened this issue Feb 7, 2023 · 1 comment

Comments

@hangsu
Copy link

hangsu commented Feb 7, 2023

Is your feature request related to a problem? Please describe.
Phlexing can't tell when to leave out the text method call on methods that render

image

Expected:

render SomeComponent.new do |c|
  c.section { "hello world" }
end

Not sure what the solution might be. Phlexing obviously doesn't know if c.section is rendering, capturing for Phlex::DeferredRender or returning a String.

@marcoroth
Copy link
Owner

marcoroth commented Feb 7, 2023

Hey @hangsu, thanks for bringing this up!

This is indeed something I haven't considered yet, and I'm actually not sure if and how we could support this.

Unless we add a rule that doesn't output the text call if the method which is being called takes in a block. But I'm not sure if that would be correct in 100% of the cases. Probably not, but it's probably more cases where that would be the more "desirable" outcome.

For the string inside the block we could do something similar as we do with regular HTML elements. Currently this:

<div>123</div>
<div><span>123</span>456</div>

gets converted to:

div { "123" }

div do
  span { "123" }
  text "456"
end

where we also omit the text call in the first example if there are other siblings. Maybe we could also do something similar for this case too.

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

No branches or pull requests

2 participants