Open tbtommyb opened 5 years ago
This really is a thorn in my side.
I think the problem comes from Airtable being a little slow. When the user is submitting new content, we fire off a POST
request to add, say, a new station and at the same time we redirect the user to the page that lists all of the stations. This page queries the database for a list of stations, but this often happens before the POST
request is fully dealt with, so the rendered list of stations doesn't include the one the user just added.
We tried wrapping the componentDidMount
Airtable query in setInterval
-- even a 10ms delay was enough -- but this caused other, bizarre problems (3460 errors in the console, for example) so we went with this awful solution.
Do you have any suggestions for an alternative?
Are you waiting to get the POST request's response code before starting the redirect?
If you have the server return a 303 code with the location of the created resource then the user's browser will redirect to it automatically (see this SO answer). This ensures that you don't try and redirect until the right time.
If you are initiating the POST request from React/client-side JS then I think you might need to do the redirect manually. If you do it in the callback of the POST request you can check that the response code is 303 and redirect then.
It's good that you commented on this but I don't really understand why it's necessary? What problem occurs if you don't have a double request?