Page crash on creating new version of manuscript
To reproduce:
- Submit a manuscript
- In the decision page set to "Revise"
- Go back to the manuscript's submission page and click "Create new version". The page will crash.
The crash is caused because in Submit.js we have handleSave
debounces set up like this, with useCallback
inside a loop that iterates over all manuscript versions. So useCallback
is called multiple times per render.
This causes a page crash when an author creates a new version of a manuscript, because then it then has one extra version, so it encounters more hooks than during the previous render, and throws an error.
I'm not sure what the correct fix should be. The debounce needs to have its state preserved between calls, and we can't sensibly combine the debounces for all the different versions. But hooks such as useCallback
shouldn't appear in conditional code or loops that can change order or count with subsequent renders.