Repository navigation
Conversation
|
I'd appreciate it if someone could add a |
|
@boardfish thanks for opening this up. Let's take the delegation route ❤️ |
|
@joelhawksley In line with a couple of other issues I've seen, particularly #1099, I'm wondering if this is symptomatic of a wider issue. It looks like it's possible to call form helpers, My worry with delegation is that we would have to list all the helpers it covers. I don't think ViewComponent needs to know which helpers the view has available to it, but |
|
@joelhawksley Did you have any further thoughts on that, or do we still want to go with delegation? |
|
@boardfish thanks for the ping. Thinking about this some more, I think we should document the existing incompatibility and push folks towards passing in a builder explicitly. Allowing global state to change the rendered output of a component seems like a tricky thing to reason about and I think we should tread carefully in making changes that support such behavior. |
|
Good to know. I'll wrap this up with that in mind soon. |
|
@joelhawksley I've rebased, and documented the issue in 0dfac56. Hopefully that makes this good to go. |
Co-authored-by: Joel Hawksley <joelhawksley@github.com>
Co-authored-by: Joel Hawksley <joelhawksley@github.com>
|
Rebased and passing the linter. Good to go? |
|
Yes, I'll merge! |
|
|
||
| ## main | ||
|
|
||
| * Add failing test for default form builder and documentation around known issue. |
There was a problem hiding this comment.
I think this is a bit confusing - it's not actually a failing test anymore, right? (It looks like the test added is a passing test that shows how to work around the known issue.)
|
|
||
| ## Forms don't use the default form builder | ||
|
|
||
| Calls to form helpers such as `form_with` in ViewComponents [don't use the default form builder](https://github.com/github/view_component/pull/1090#issue-753331927). This is by design, as it allows global state to change the rendered output of a component. Instead, consider passing a form builder into form helpers via the `builder` argument: |
There was a problem hiding this comment.
"This is by design, as it allows global state to change the rendered output of a component" is also kind of confusing to me - it seems to read as if we designed ViewComponent such that global state can change the rendered output, when it's actually been designed to avoid that.
If I'm understanding it correctly, perhaps something like "This is by design because doing so would allow..." could be a clearer way to communicate this. What do you think?
There was a problem hiding this comment.
Agree, the phrasing is awkward.
| Calls to form helpers such as `form_with` in ViewComponents [don't use the default form builder](https://github.com/github/view_component/pull/1090#issue-753331927). This is by design, as it allows global state to change the rendered output of a component. Instead, consider passing a form builder into form helpers via the `builder` argument: | |
| Calls to form helpers such as `form_with` in ViewComponents [don't use the default form builder](https://github.com/github/view_component/pull/1090#issue-753331927). This is by design, as it would otherwise allow global state to change the rendered output of a component. Instead, consider passing a form builder into form helpers via the `builder` argument: |
| with_controller_class DefaultFormBuilderController do | ||
| render_inline(DefaultFormBuilderComponent.new) | ||
|
|
||
| assert_text("changed by default form builder") |
There was a problem hiding this comment.
Following up on my first comment, I'm wondering if it'd be helpful to complement this test with one that doesn't use helpers.fields in order to show that the effect would be the opposite in that case (i.e. the default form builder would be ignored). Is that the known issue that we want to document?
(Perhaps it'd even help to add a third test that doesn't use helpers. but does pass the builder explicitly, such that the test cases would document all the ways to go about it.)
|
Thanks for your feedback @rmacklin - I'll create a follow-up PR to address these issues. |
Summary
When form helpers are called directly, the default form builder is not used and must be specified. For example, calling this:
does not use the default form builder. Either manually specifying the
builder:argument tofieldsor callinghelpers.fields(as I have in the tests here) works, though.I feel that this is a little unintuitive - it's odd that form helpers do work directly within ViewComponent but do not inherit the default form builder specified by the controller. I feel that they should either raise an error or be delegated to
helpersby default.