From 5e936e267c64f0a64eaf9b8efc7ed68a191f8448 Mon Sep 17 00:00:00 2001 From: Anand Srinivasan <66776129+eco-monk@users.noreply.github.com> Date: Fri, 14 Apr 2023 08:19:43 +0530 Subject: [PATCH] fix: 503 error fixed when navigating to homepage (#21971) TL;DR 503 error fixed when navigating to homepage while the editor is loading. - `RESET_EDITOR_REQUEST` is an action that removes `currentApplication` from the `applicationsReducer`. - When starting the editor, appEngine saga has an action `completeChore` which reads the `currentApplication` object. - Now, when we go back to homepage (while the editor is still initializing) - `RESET_EDITOR_REQUEST` is dispatched (so `currentApplication` is cleared) - the appEngine still runs in the background and tries to read `currentApplication` throwing an error. Now we make sure appEngine is cancelled whenever `RESET_EDITOR_REQUEST` is triggered. A follow up task to investigate how errors are thrown in app editor saga: #21972 Fixes #21915 ## Media Before: https://www.loom.com/share/eae1eeeec04f4b35a9d3be6ea8177b0a After: https://www.loom.com/share/09c328f81d8344569c0ff0b7a3d97713 --- app/client/src/sagas/InitSagas.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/client/src/sagas/InitSagas.ts b/app/client/src/sagas/InitSagas.ts index 27956999e8..72c544d49c 100644 --- a/app/client/src/sagas/InitSagas.ts +++ b/app/client/src/sagas/InitSagas.ts @@ -148,10 +148,22 @@ function* updateURLSaga(action: ReduxURLChangeAction) { }); } +function* appEngineSaga(action: ReduxAction) { + yield race({ + task: call(startAppEngine, action), + cancel: take(ReduxActionTypes.RESET_EDITOR_REQUEST), + }); +} + export default function* watchInitSagas() { yield all([ - takeLatest(ReduxActionTypes.INITIALIZE_EDITOR, startAppEngine), - takeLatest(ReduxActionTypes.INITIALIZE_PAGE_VIEWER, startAppEngine), + takeLatest( + [ + ReduxActionTypes.INITIALIZE_EDITOR, + ReduxActionTypes.INITIALIZE_PAGE_VIEWER, + ], + appEngineSaga, + ), takeLatest(ReduxActionTypes.RESET_EDITOR_REQUEST, resetEditorSaga), takeEvery(URL_CHANGE_ACTIONS, updateURLSaga), ]);