-
Notifications
You must be signed in to change notification settings - Fork 50.4k
Warn when formAction is used without a form #26755
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
base: main
Are you sure you want to change the base?
Conversation
|
Comparing: fda1f0b...fed72e3 Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: (No significant changes) |
24246d2 to
75c948c
Compare
sebmarkbage
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't limited to formActions as functions but applies to all formAction non-null values on input/button. Since we also track nesting of DOM nodes we should be able to warn about this earlier instead of waiting for the action to be invoked.
How about we do the warning in the render phase by checking DOM nesting instead?
The risk is that we don't know if you're rendering the React root into a form but we can either just assume that you're not and warn. Seems like such an edge case or check at the root.
|
Yeah I figured I'd not add warnings for existing code and I was thinking the non-React form container might happen. But you're right it's probably rare so maybe we just should. |
|
Even if we add the warning for non-functions for existing code behind a flag for later, it seems nicer to get the warning earlier rather than later. Since this is something that seems like you could accidentally do even during a simple refactor. Another interesting thing is that we don't warn for nested forms in the case where you render into one so you might be tempted to add one as a wrapper when you get this warning which wouldn't be quite correct. Although it probably works as long as it's not SSR. |
a397c10 to
ee4c4a0
Compare
ee4c4a0 to
fed72e3
Compare
|
Weirdly we would catch invalid form nesting if the container is a form, but not if the container is inside a form. I left that logic as-is for now. I suppose since you can reparent containers that makes sense in some sense. For SSR into a form ancestor you wouldn't get the warning but you would get the hydration error, which seems fine since it should be rare. With diffInCommitPhase it looks like the bindings currently don't have access to hostContext anytime during updates. |
No description provided.