From a22fda4b6ef8995142cedb7ec9493c1c3f4efc7e Mon Sep 17 00:00:00 2001 From: dudeami0 <dudeami0@gmail.com> Date: Thu, 22 Jun 2023 23:30:42 -0400 Subject: [PATCH] Fix server-side rendering after first load. --- src/shared/components/community/communities.tsx | 3 ++- src/shared/components/community/community.tsx | 3 ++- src/shared/components/home/admin-settings.tsx | 3 ++- src/shared/components/home/home.tsx | 3 ++- src/shared/components/home/instances.tsx | 3 ++- src/shared/components/modlog.tsx | 3 ++- src/shared/components/person/inbox.tsx | 3 ++- src/shared/components/person/profile.tsx | 8 ++++++-- .../components/person/registration-applications.tsx | 3 ++- src/shared/components/person/reports.tsx | 3 ++- src/shared/components/post/create-post.tsx | 3 ++- src/shared/components/post/post.tsx | 2 +- .../components/private_message/create-private-message.tsx | 3 ++- src/shared/components/search.tsx | 8 ++++++-- 14 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/shared/components/community/communities.tsx b/src/shared/components/community/communities.tsx index a84ec05..35e89c3 100644 --- a/src/shared/components/community/communities.tsx +++ b/src/shared/components/community/communities.tsx @@ -5,6 +5,7 @@ import { setIsoData, showLocal, } from "@utils/app"; +import { isBrowser } from "@utils/browser"; import { getPageFromString, getQueryParams, @@ -67,7 +68,7 @@ export class Communities extends Component<any, CommunitiesState> { this.handleListingTypeChange = this.handleListingTypeChange.bind(this); // Only fetch the data if coming from another route - if (FirstLoadService.isFirstLoad) { + if (!isBrowser() || FirstLoadService.isFirstLoad) { const { listCommunitiesResponse } = this.isoData.routeData; this.state = { diff --git a/src/shared/components/community/community.tsx b/src/shared/components/community/community.tsx index 111b47c..3e7615a 100644 --- a/src/shared/components/community/community.tsx +++ b/src/shared/components/community/community.tsx @@ -15,6 +15,7 @@ import { updateCommunityBlock, updatePersonBlock, } from "@utils/app"; +import { isBrowser } from "@utils/browser"; import { getPageFromString, getQueryParams, @@ -197,7 +198,7 @@ export class Community extends Component< this.handleFeaturePost = this.handleFeaturePost.bind(this); // Only fetch the data if coming from another route - if (FirstLoadService.isFirstLoad) { + if (!isBrowser() || FirstLoadService.isFirstLoad) { const { communityRes, commentsRes, postsRes } = this.isoData.routeData; this.state = { diff --git a/src/shared/components/home/admin-settings.tsx b/src/shared/components/home/admin-settings.tsx index 7ac69fe..6ab5b65 100644 --- a/src/shared/components/home/admin-settings.tsx +++ b/src/shared/components/home/admin-settings.tsx @@ -4,6 +4,7 @@ import { setIsoData, showLocal, } from "@utils/app"; +import { isBrowser } from "@utils/browser"; import { capitalizeFirstLetter } from "@utils/helpers"; import { RouteDataResponse } from "@utils/types"; import classNames from "classnames"; @@ -74,7 +75,7 @@ export class AdminSettings extends Component<any, AdminSettingsState> { this.handleCreateEmoji = this.handleCreateEmoji.bind(this); // Only fetch the data if coming from another route - if (FirstLoadService.isFirstLoad) { + if (!isBrowser() || FirstLoadService.isFirstLoad) { const { bannedRes, instancesRes } = this.isoData.routeData; this.state = { diff --git a/src/shared/components/home/home.tsx b/src/shared/components/home/home.tsx index bad771f..da1be70 100644 --- a/src/shared/components/home/home.tsx +++ b/src/shared/components/home/home.tsx @@ -13,6 +13,7 @@ import { showLocal, updatePersonBlock, } from "@utils/app"; +import { isBrowser } from "@utils/browser"; import { getPageFromString, getQueryParams, @@ -263,7 +264,7 @@ export class Home extends Component<any, HomeState> { this.handleFeaturePost = this.handleFeaturePost.bind(this); // Only fetch the data if coming from another route - if (FirstLoadService.isFirstLoad) { + if (!isBrowser() || FirstLoadService.isFirstLoad) { const { trendingCommunitiesRes, commentsRes, postsRes } = this.isoData.routeData; diff --git a/src/shared/components/home/instances.tsx b/src/shared/components/home/instances.tsx index b54c96a..9c38cf4 100644 --- a/src/shared/components/home/instances.tsx +++ b/src/shared/components/home/instances.tsx @@ -1,4 +1,5 @@ import { setIsoData } from "@utils/app"; +import { isBrowser } from "@utils/browser"; import { RouteDataResponse } from "@utils/types"; import { Component } from "inferno"; import { @@ -35,7 +36,7 @@ export class Instances extends Component<any, InstancesState> { super(props, context); // Only fetch the data if coming from another route - if (FirstLoadService.isFirstLoad) { + if (!isBrowser() || FirstLoadService.isFirstLoad) { this.state = { ...this.state, instancesRes: this.isoData.routeData.federatedInstancesResponse, diff --git a/src/shared/components/modlog.tsx b/src/shared/components/modlog.tsx index 722f6e7..e8c707e 100644 --- a/src/shared/components/modlog.tsx +++ b/src/shared/components/modlog.tsx @@ -5,6 +5,7 @@ import { personToChoice, setIsoData, } from "@utils/app"; +import { isBrowser } from "@utils/browser"; import { debounce, getIdFromString, @@ -660,7 +661,7 @@ export class Modlog extends Component< this.handleModChange = this.handleModChange.bind(this); // Only fetch the data if coming from another route - if (FirstLoadService.isFirstLoad) { + if (!isBrowser() || FirstLoadService.isFirstLoad) { const { res, communityRes, modUserResponse, userResponse } = this.isoData.routeData; diff --git a/src/shared/components/person/inbox.tsx b/src/shared/components/person/inbox.tsx index 395875b..3c91370 100644 --- a/src/shared/components/person/inbox.tsx +++ b/src/shared/components/person/inbox.tsx @@ -11,6 +11,7 @@ import { setIsoData, updatePersonBlock, } from "@utils/app"; +import { isBrowser } from "@utils/browser"; import { RouteDataResponse } from "@utils/types"; import { Component, linkEvent } from "inferno"; import { @@ -163,7 +164,7 @@ export class Inbox extends Component<any, InboxState> { this.handleEditMessage = this.handleEditMessage.bind(this); // Only fetch the data if coming from another route - if (FirstLoadService.isFirstLoad) { + if (!isBrowser() || FirstLoadService.isFirstLoad) { const { mentionsRes, messagesRes, repliesRes } = this.isoData.routeData; this.state = { diff --git a/src/shared/components/person/profile.tsx b/src/shared/components/person/profile.tsx index d000368..6e0530d 100644 --- a/src/shared/components/person/profile.tsx +++ b/src/shared/components/person/profile.tsx @@ -10,7 +10,11 @@ import { setIsoData, updatePersonBlock, } from "@utils/app"; -import { restoreScrollPosition, saveScrollPosition } from "@utils/browser"; +import { + isBrowser, + restoreScrollPosition, + saveScrollPosition, +} from "@utils/browser"; import { capitalizeFirstLetter, futureDaysToUnixTime, @@ -206,7 +210,7 @@ export class Profile extends Component< this.handleFeaturePost = this.handleFeaturePost.bind(this); // Only fetch the data if coming from another route - if (FirstLoadService.isFirstLoad) { + if (!isBrowser() || FirstLoadService.isFirstLoad) { this.state = { ...this.state, personRes: this.isoData.routeData.personResponse, diff --git a/src/shared/components/person/registration-applications.tsx b/src/shared/components/person/registration-applications.tsx index d9eb6ad..5e92c07 100644 --- a/src/shared/components/person/registration-applications.tsx +++ b/src/shared/components/person/registration-applications.tsx @@ -3,6 +3,7 @@ import { myAuthRequired, setIsoData, } from "@utils/app"; +import { isBrowser } from "@utils/browser"; import { RouteDataResponse } from "@utils/types"; import { Component, linkEvent } from "inferno"; import { @@ -58,7 +59,7 @@ export class RegistrationApplications extends Component< this.handleApproveApplication = this.handleApproveApplication.bind(this); // Only fetch the data if coming from another route - if (FirstLoadService.isFirstLoad) { + if (!isBrowser() || FirstLoadService.isFirstLoad) { this.state = { ...this.state, appsRes: this.isoData.routeData.listRegistrationApplicationsResponse, diff --git a/src/shared/components/person/reports.tsx b/src/shared/components/person/reports.tsx index 8f5eaf3..9d04c8a 100644 --- a/src/shared/components/person/reports.tsx +++ b/src/shared/components/person/reports.tsx @@ -5,6 +5,7 @@ import { myAuthRequired, setIsoData, } from "@utils/app"; +import { isBrowser } from "@utils/browser"; import { amAdmin } from "@utils/roles"; import { RouteDataResponse } from "@utils/types"; import { Component, linkEvent } from "inferno"; @@ -108,7 +109,7 @@ export class Reports extends Component<any, ReportsState> { this.handleResolvePrivateMessageReport.bind(this); // Only fetch the data if coming from another route - if (FirstLoadService.isFirstLoad) { + if (!isBrowser() || FirstLoadService.isFirstLoad) { const { commentReportsRes, postReportsRes, messageReportsRes } = this.isoData.routeData; diff --git a/src/shared/components/post/create-post.tsx b/src/shared/components/post/create-post.tsx index fe94183..ed686f3 100644 --- a/src/shared/components/post/create-post.tsx +++ b/src/shared/components/post/create-post.tsx @@ -1,4 +1,5 @@ import { enableDownvotes, enableNsfw, myAuth, setIsoData } from "@utils/app"; +import { isBrowser } from "@utils/browser"; import { getIdFromString, getQueryParams } from "@utils/helpers"; import type { QueryParams } from "@utils/types"; import { Choice, RouteDataResponse } from "@utils/types"; @@ -69,7 +70,7 @@ export class CreatePost extends Component< this.handleSelectedCommunityChange.bind(this); // Only fetch the data if coming from another route - if (FirstLoadService.isFirstLoad) { + if (!isBrowser() || FirstLoadService.isFirstLoad) { const { communityResponse: communityRes, initialCommunitiesRes } = this.isoData.routeData; diff --git a/src/shared/components/post/post.tsx b/src/shared/components/post/post.tsx index f0aa3ff..54823f2 100644 --- a/src/shared/components/post/post.tsx +++ b/src/shared/components/post/post.tsx @@ -174,7 +174,7 @@ export class Post extends Component<any, PostState> { this.state = { ...this.state, commentSectionRef: createRef() }; // Only fetch the data if coming from another route - if (FirstLoadService.isFirstLoad) { + if (!isBrowser() || FirstLoadService.isFirstLoad) { const { commentsRes, postRes } = this.isoData.routeData; this.state = { diff --git a/src/shared/components/private_message/create-private-message.tsx b/src/shared/components/private_message/create-private-message.tsx index 8afd348..89ed759 100644 --- a/src/shared/components/private_message/create-private-message.tsx +++ b/src/shared/components/private_message/create-private-message.tsx @@ -1,4 +1,5 @@ import { getRecipientIdFromProps, myAuth, setIsoData } from "@utils/app"; +import { isBrowser } from "@utils/browser"; import { RouteDataResponse } from "@utils/types"; import { Component } from "inferno"; import { @@ -44,7 +45,7 @@ export class CreatePrivateMessage extends Component< this.handlePrivateMessageCreate.bind(this); // Only fetch the data if coming from another route - if (FirstLoadService.isFirstLoad) { + if (!isBrowser() || FirstLoadService.isFirstLoad) { this.state = { ...this.state, recipientRes: this.isoData.routeData.recipientDetailsResponse, diff --git a/src/shared/components/search.tsx b/src/shared/components/search.tsx index 473b18c..3d04c50 100644 --- a/src/shared/components/search.tsx +++ b/src/shared/components/search.tsx @@ -11,7 +11,11 @@ import { setIsoData, showLocal, } from "@utils/app"; -import { restoreScrollPosition, saveScrollPosition } from "@utils/browser"; +import { + isBrowser, + restoreScrollPosition, + saveScrollPosition, +} from "@utils/browser"; import { capitalizeFirstLetter, debounce, @@ -270,7 +274,7 @@ export class Search extends Component<any, SearchState> { }; // Only fetch the data if coming from another route - if (FirstLoadService.isFirstLoad) { + if (!isBrowser() || FirstLoadService.isFirstLoad) { const { communityResponse: communityRes, creatorDetailsResponse: creatorDetailsRes, -- 2.44.1