marmelab / react-admin

A frontend Framework for single-page applications on top of REST/GraphQL APIs, using TypeScript, React and Material Design
http://marmelab.com/react-admin
MIT License
24.84k stars 5.23k forks source link

Chrome will not pre-populate your "create comment" for post with string id until browser refresh in sandbox #3813

Closed gregbelyea71 closed 4 years ago

gregbelyea71 commented 4 years ago

What you were expecting: Same behaviour as your sandbox example for "react-admin-advanced-recipes-create-a-record-related-to-the-current-one"... I expected to have a String ID with spaces still prepopulate the dropdown and have created date show up in comment... It used to work

What happened instead: Page shows up empty form, and will not populate until you hit refresh on the browser

Steps to reproduce: Changed react-admin to 2.9.7, changed your id's on first two records to strings with spaces, selected the first post, went to comments tab, selected add a new comment, nothing pre populates in Chrome until you hit refresh on browser.... I tested in Microsoft Edge and it pre-populates fine

Related code: https://codesandbox.io/s/react-admin-advanced-recipes-create-a-record-related-to-the-current-one-vrusd

Environment

djhi commented 4 years ago

You have to call decodeURIComponent with the id from the location:

  // Read the post_id from the location which is injected by React Router and passed to our component by react-admin automatically
  const { post_id: post_id_string } = parse(props.location.search);

  // ra-data-fakerest uses integers as identifiers, we need to parse the querystring
  // We also must ensure we can still create a new comment without having a post_id
  // from the url by returning an empty string if post_id isn't specified
  const post_id = post_id_string ? decodeURIComponent(post_id_string) : '';
gregbelyea71 commented 4 years ago

@djhi

I tried that previously and it made no difference.. i just put it into the sandbox and the behaviour is the same. Without hitting refresh in the browser... no dice

https://codesandbox.io/s/react-admin-advanced-recipes-create-a-record-related-to-the-current-one-vrusd