Skip to content

Fix infinite ♾️ remix loop when BYPASS_AUTH set in editor-api#1007

Merged
floehopper merged 1 commit intomainfrom
fix-infinite-loop-when-remixing-project-with-bypass-auth-set-in-editor-api
May 13, 2024
Merged

Fix infinite ♾️ remix loop when BYPASS_AUTH set in editor-api#1007
floehopper merged 1 commit intomainfrom
fix-infinite-loop-when-remixing-project-with-bypass-auth-set-in-editor-api

Conversation

@floehopper
Copy link
Contributor

@floehopper floehopper commented May 13, 2024

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.

builder.addCase("editor/saveProject/pending", (state) => {
state.saving = "pending";
state.saveTriggered = false;
});

builder.addCase("editor/remixProject/pending", (state, action) => {
state.saving = "pending";
});

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.

@github-actions
Copy link

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 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 [1] 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)` [2]
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.

[1]: https://github.com/RaspberryPiFoundation/editor-ui/blob/2df8a9761bff2de4824a7815252eb62560e85356/src/hooks/useProjectPersistence.js#L23
[2]: https://github.com/RaspberryPiFoundation/editor-ui/blob/2df8a9761bff2de4824a7815252eb62560e85356/src/hooks/useProjectPersistence.js#L24
@github-actions
Copy link

Copy link
Contributor

@loiswells97 loiswells97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks for fixing this 👍

@floehopper floehopper merged commit bc33810 into main May 13, 2024
@floehopper floehopper deleted the fix-infinite-loop-when-remixing-project-with-bypass-auth-set-in-editor-api branch May 13, 2024 15:00
@floehopper floehopper changed the title Fix infinite remix loop when BYPASS_AUTH set in editor-api Fix infinite ♾️ remix loop when BYPASS_AUTH set in editor-api May 14, 2024
@floehopper floehopper mentioned this pull request Jun 3, 2024
floehopper added a commit that referenced this pull request Jun 4, 2024
### Added

- Add `project_name_editable` attribute to web component (#1009)
- Fires custom event when the theme changes (#1015)
- Add `output_only` attribute to web component (#1019 & originally #782)
- Add `assets_identifier` attribute to web component (#1019 & originally
#901)
- Enhance `code` attribute on web component to override project main
component content (#1019 & originally #901)
- Add `runCode`, `stopCode` & `rerunCode` methods to web component
(#1019 & originally #899)
- Send error details in "editor-runCompleted" event (#1019 & originally
#915)
- Return error details to web component (#1019 & originally #915)
- Add `output_panels` attribute to web component (#1019 & originally
#909)

### Changed

- Remove unused `/embedded/projects/:identifier` route (#1013)

### Fixed

- Remove unused `REACT_APP_LOGIN_ENABLED` env var (#1006)
- Fix infinite remix loop when `BYPASS_AUTH` set in `editor-api` (#1007)
- Fixes for docker-compose.yml (#1008)
- Fix deprecation warnings in GitHub Actions (#1011)
- Removed unused `isEmbedded` param from `useProject` call in
`EmbeddedViewer` (#1016)
- Improvements to Cypress specs in CI (#1017)
- Fix warnings and verbose output when starting Webpack Dev Server
(#1018)
- Add e2e spec for project remix behaviour in web component (#1020)
- Fix initial value of `user` in `WebComponentLoader` (#1021)
- Make `authKey` in e2e web component spec more realistic (#1022)
- Remove unused `ComponentStore` (#1023)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants