Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix issue with forking #35988

Merged
merged 10 commits into from
Sep 5, 2024
6 changes: 1 addition & 5 deletions app/client/src/ce/sagas/ApplicationSagas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,7 @@ export function* fetchAppAndPagesSaga(
) {
try {
const { pages, ...payload } = action.payload;
const request = {
applicationId: payload.applicationId,
pageId: payload.pageId,
mode: payload.mode,
};
const request = { ...payload };
if (request.pageId && request.applicationId) {
delete request.applicationId;
}
Expand Down
41 changes: 24 additions & 17 deletions app/client/src/pages/Editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ interface EditorProps {
type Props = EditorProps & RouteComponentProps<BuilderRouteParams>;

class Editor extends Component<Props> {
prevPageId: string | null = null;

componentDidMount() {
const { basePageId } = this.props.match.params || {};
urlBuilder.setCurrentBasePageId(basePageId);
Expand Down Expand Up @@ -110,7 +112,24 @@ class Editor extends Component<Props> {

componentDidUpdate(prevProps: Props) {
const { baseApplicationId, basePageId } = this.props.match.params || {};
const { basePageId: prevPageBaseId } = prevProps.match.params || {};
const { basePageId: prevBasePageId } = prevProps.match.params || {};

const pageId = this.props.pages.find(
(page) => page.basePageId === basePageId,
)?.pageId;

const prevPageId = prevProps.pages.find(
(page) => page.basePageId === prevBasePageId,
)?.pageId;
// caching value for prevPageId as it is required in future lifecycles
if (prevPageId) {
this.prevPageId = prevPageId;
}

const isPageIdUpdated = pageId !== this.prevPageId;
const isBasePageIdUpdated = basePageId !== prevBasePageId;
const isPageUpdated = isPageIdUpdated || isBasePageIdUpdated;

const isBranchUpdated = getIsBranchUpdated(
this.props.location,
prevProps.location,
Expand All @@ -125,8 +144,6 @@ class Editor extends Component<Props> {
GIT_BRANCH_QUERY_KEY,
);

const isPageIdUpdated = basePageId !== prevPageBaseId;

// to prevent re-init during connect
if (prevBranch && isBranchUpdated && basePageId) {
this.props.initEditor({
Expand All @@ -141,20 +158,10 @@ class Editor extends Component<Props> {
* If we don't check for `prevPageId`: fetch page is re triggered
* when redirected to the default page
*/
if (
prevPageBaseId &&
basePageId &&
isPageIdUpdated &&
this.props.pages.length
) {
const pageId = this.props.pages.find(
(page) => page.basePageId === basePageId,
)?.pageId;
if (pageId) {
this.props.updateCurrentPage(pageId);
this.props.setupPage(pageId);
urlBuilder.setCurrentBasePageId(basePageId);
}
if (pageId && this.prevPageId && isPageUpdated) {
this.props.updateCurrentPage(pageId);
this.props.setupPage(pageId);
urlBuilder.setCurrentBasePageId(basePageId);
}
}
}
Expand Down
Loading