Previously when BYPASS_AUTH was set to true in editor-api and a remix was triggered in editor-ui, the editor went into an ♾️ infinite loop creating remix after remix after remix of the same project...
This was happening, because saveTriggered was never being set to false in the "editor/remixProject/pending" case in EditorSlice like it is being in "editor/saveProject/pending". Thus this condition in the useProjectPersistence hook was always true and syncProject("remix") was repeatedly dispatched.
We were somehow (mostly?) getting away with this when BYPASS_AUTH was not set in editor-ui, because of the extra time taken to make real authentication requests from within the API request to create the remixed project. This meant that by the time the useProjectPersistence hook was executed for the 2nd time, isOwner(user, project) returned true and so syncProject("save") was dispatched instead of syncProject("remix"). This in turn meant that the "editor/saveProject/pending" case was executed and thus saveTriggered was set to false preventing the infinite loop at the cost of an unintended/unnecessary save of the remixed project just created.
By setting saveTriggered to false in the "editor/remixProject/pending" case like we do in the "editor/saveProject/pending" case, we can prevent the infinite loop and the extra saving of the project.
Previously when
BYPASS_AUTH
was set totrue
ineditor-api
and a remix was triggered ineditor-ui
, the editor went into an ♾️ infinite loop creating remix after remix after remix of the same project...This was happening, because
saveTriggered
was never being set tofalse
in the "editor/remixProject/pending" case inEditorSlice
like it is being in "editor/saveProject/pending". Thus this condition in theuseProjectPersistence
hook was alwaystrue
andsyncProject("remix")
was repeatedly dispatched.https://github.com/RaspberryPiFoundation/editor-ui/blob/2df8a9761bff2de4824a7815252eb62560e85356/src/redux/EditorSlice.js#L372-L375
https://github.com/RaspberryPiFoundation/editor-ui/blob/2df8a9761bff2de4824a7815252eb62560e85356/src/redux/EditorSlice.js#L397-L399
We were somehow (mostly?) getting away with this when
BYPASS_AUTH
was not set ineditor-ui
, because of the extra time taken to make real authentication requests from within the API request to create the remixed project. This meant that by the time theuseProjectPersistence
hook was executed for the 2nd time,isOwner(user, project)
returnedtrue
and sosyncProject("save")
was dispatched instead ofsyncProject("remix")
. This in turn meant that the "editor/saveProject/pending" case was executed and thussaveTriggered
was set tofalse
preventing the infinite loop at the cost of an unintended/unnecessary save of the remixed project just created.By setting
saveTriggered
tofalse
in the "editor/remixProject/pending" case like we do in the "editor/saveProject/pending" case, we can prevent the infinite loop and the extra saving of the project.