Skip to content

Commit

Permalink
chore: Fix appsmith store hydration from localstorage in view mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ashit-rath committed Feb 20, 2025
1 parent 084ba0f commit d9c5c62
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
17 changes: 6 additions & 11 deletions app/client/src/entities/Engine/AppEditorEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { resetEditorSuccess } from "actions/initActions";
import {
fetchAllPageEntityCompletion,
setupPageAction,
updateAppStore,
} from "actions/pageActions";
import {
executePageLoadActions,
Expand Down Expand Up @@ -74,8 +73,8 @@ import {
selectGitApplicationCurrentBranch,
selectGitModEnabled,
} from "selectors/gitModSelectors";
import { getPersistentAppStore } from "constants/AppConstants";
import { applicationArtifact } from "git-artifact-helpers/application";
import log from "loglevel";

export default class AppEditorEngine extends AppEngine {
constructor(mode: APP_MODE) {
Expand Down Expand Up @@ -303,23 +302,19 @@ export default class AppEditorEngine extends AppEngine {
if (isGitPersistBranchEnabled) {
const currentUser: User = yield select(getCurrentUser);

if (currentUser.email && currentApplication?.baseId && currentBranch) {
if (currentUser?.email && currentApplication?.baseId && currentBranch) {
yield setLatestGitBranchInLocal(
currentUser.email,
currentApplication.baseId,
currentBranch,
);
} else {
log.error(
`There was an error setting the latest git branch in local - userEmail: ${!!currentUser?.email}, applicationId: ${currentApplication?.baseId}, branch: ${currentBranch}`,
);
}
}

if (currentApplication?.id) {
yield put(
updateAppStore(
getPersistentAppStore(currentApplication.id, currentBranch),
),
);
}

const [isAnotherEditorTabOpen, currentTabs] = yield call(
trackOpenEditorTabs,
currentApplication.id,
Expand Down
15 changes: 13 additions & 2 deletions app/client/src/entities/Engine/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { fetchApplication } from "ee/actions/applicationActions";
import { setAppMode } from "actions/pageActions";
import { setAppMode, updateAppStore } from "actions/pageActions";
import type { ApplicationPayload } from "entities/Application";
import {
ReduxActionErrorTypes,
Expand All @@ -19,6 +19,8 @@ import { updateBranchLocally } from "actions/gitSyncActions";
import { restoreIDEEditorViewMode } from "actions/ideActions";
import type { Span } from "instrumentation/types";
import { endSpan, startNestedSpan } from "instrumentation/generateTraces";
import { selectGitApplicationCurrentBranch } from "selectors/gitModSelectors";
import { getPersistentAppStore } from "constants/AppConstants";

export interface AppEnginePayload {
applicationId?: string;
Expand Down Expand Up @@ -85,7 +87,7 @@ export default abstract class AppEngine {
rootSpan: Span,
) {
const loadAppDataSpan = startNestedSpan("AppEngine.loadAppData", rootSpan);
const { applicationId, basePageId } = payload;
const { applicationId, basePageId, branch } = payload;
const { pages } = allResponses;
const page = pages.data?.pages?.find((page) => page.baseId === basePageId);
const apiCalls: boolean = yield failFastApiCalls(
Expand All @@ -112,6 +114,15 @@ export default abstract class AppEngine {
}

const application: ApplicationPayload = yield select(getCurrentApplication);
const currentBranch: string | undefined = yield select(
selectGitApplicationCurrentBranch,
);

yield put(
updateAppStore(
getPersistentAppStore(application.id, branch || currentBranch),
),
);

const defaultPageId: string = yield select(getDefaultPageId);
const defaultPageBaseId: string = yield select(getDefaultBasePageId);
Expand Down

0 comments on commit d9c5c62

Please sign in to comment.