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

[Bug]: When submitting a <Form>, the state overwrites to null #10629

Closed
josh-sanger opened this issue Jun 22, 2023 · 3 comments · Fixed by #10630
Closed

[Bug]: When submitting a <Form>, the state overwrites to null #10629

josh-sanger opened this issue Jun 22, 2023 · 3 comments · Fixed by #10630
Labels

Comments

@josh-sanger
Copy link

josh-sanger commented Jun 22, 2023

What version of React Router are you using?

Lastest

Steps to Reproduce

  1. Save some state to location.state
  2. Submit a <Form>
  3. Log the location.state after action returns;

Expected Behavior

It would be great it would could pass in the current state or new state via <Form state> (like the <Link> component)

Actual Behavior

There is no ability to send state with a <Form> navigation and it automatically resets to null

@timdorr
Copy link
Member

timdorr commented Jun 22, 2023

This is because we're doing a navigation that you don't have direct access to.

Your best bet is to send over the state data as a type="hidden" input along with the rest of the form. Then you can retain it as the form is submitted and choose to carry it to future navigations.

@brophdawg11
Copy link
Contributor

brophdawg11 commented Jun 22, 2023

Going to reopen since I asked Josh to open this 😄

I think the bug is not so much that we don't preserve externally-set location.state, but that we don't provide <Form state> just like we support <Link state> since both are router/history navigations under the hood. That way folks could proxy along current state if needed.

@brophdawg11 brophdawg11 reopened this Jun 22, 2023
@brophdawg11 brophdawg11 linked a pull request Jun 30, 2023 that will close this issue
@brophdawg11 brophdawg11 added the awaiting release This issue have been fixed and will be released soon label Jun 30, 2023
@brophdawg11
Copy link
Contributor

This is fixed in #10630 and should be available in the next release (6.14.2 or 6.15.0)

@brophdawg11 brophdawg11 removed the awaiting release This issue have been fixed and will be released soon label Aug 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants