From 2c85c87e4494210f55522653deb8e552b84cbc23 Mon Sep 17 00:00:00 2001 From: dudeami0 Date: Thu, 22 Jun 2023 23:30:42 -0400 Subject: [PATCH 1/5] 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 a84ec055..35e89c36 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 { 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 111b47cd..3e7615a9 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 7ac69fed..6ab5b659 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 { 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 bad771fc..da1be70b 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 { 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 b54c96af..9c38cf41 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 { 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 722f6e70..e8c707ed 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 395875be..3c913701 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 { 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 d0003687..6e0530d9 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 d9eb6ad0..5e92c073 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 8f5eaf36..9d04c8a7 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 { 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 fe941830..ed686f31 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 f0aa3ff5..54823f22 100644 --- a/src/shared/components/post/post.tsx +++ b/src/shared/components/post/post.tsx @@ -174,7 +174,7 @@ export class Post extends Component { 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 8afd3488..89ed7598 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 473b18c4..3d04c500 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 { }; // Only fetch the data if coming from another route - if (FirstLoadService.isFirstLoad) { + if (!isBrowser() || FirstLoadService.isFirstLoad) { const { communityResponse: communityRes, creatorDetailsResponse: creatorDetailsRes, From d706b6ba27866ad8b57d9b48743f04e63ba2dcbe Mon Sep 17 00:00:00 2001 From: dudeami0 Date: Fri, 23 Jun 2023 01:04:03 -0400 Subject: [PATCH 2/5] Moved `!isBrowser()` check to `FirstLoadServer.isFirstLoad` --- 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 ++------ src/shared/services/FirstLoadService.ts | 4 +++- 15 files changed, 19 insertions(+), 36 deletions(-) diff --git a/src/shared/components/community/communities.tsx b/src/shared/components/community/communities.tsx index 35e89c36..a84ec055 100644 --- a/src/shared/components/community/communities.tsx +++ b/src/shared/components/community/communities.tsx @@ -5,7 +5,6 @@ import { setIsoData, showLocal, } from "@utils/app"; -import { isBrowser } from "@utils/browser"; import { getPageFromString, getQueryParams, @@ -68,7 +67,7 @@ export class Communities extends Component { this.handleListingTypeChange = this.handleListingTypeChange.bind(this); // Only fetch the data if coming from another route - if (!isBrowser() || FirstLoadService.isFirstLoad) { + if (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 3e7615a9..111b47cd 100644 --- a/src/shared/components/community/community.tsx +++ b/src/shared/components/community/community.tsx @@ -15,7 +15,6 @@ import { updateCommunityBlock, updatePersonBlock, } from "@utils/app"; -import { isBrowser } from "@utils/browser"; import { getPageFromString, getQueryParams, @@ -198,7 +197,7 @@ export class Community extends Component< this.handleFeaturePost = this.handleFeaturePost.bind(this); // Only fetch the data if coming from another route - if (!isBrowser() || FirstLoadService.isFirstLoad) { + if (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 6ab5b659..7ac69fed 100644 --- a/src/shared/components/home/admin-settings.tsx +++ b/src/shared/components/home/admin-settings.tsx @@ -4,7 +4,6 @@ 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"; @@ -75,7 +74,7 @@ export class AdminSettings extends Component { this.handleCreateEmoji = this.handleCreateEmoji.bind(this); // Only fetch the data if coming from another route - if (!isBrowser() || FirstLoadService.isFirstLoad) { + if (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 da1be70b..bad771fc 100644 --- a/src/shared/components/home/home.tsx +++ b/src/shared/components/home/home.tsx @@ -13,7 +13,6 @@ import { showLocal, updatePersonBlock, } from "@utils/app"; -import { isBrowser } from "@utils/browser"; import { getPageFromString, getQueryParams, @@ -264,7 +263,7 @@ export class Home extends Component { this.handleFeaturePost = this.handleFeaturePost.bind(this); // Only fetch the data if coming from another route - if (!isBrowser() || FirstLoadService.isFirstLoad) { + if (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 9c38cf41..b54c96af 100644 --- a/src/shared/components/home/instances.tsx +++ b/src/shared/components/home/instances.tsx @@ -1,5 +1,4 @@ import { setIsoData } from "@utils/app"; -import { isBrowser } from "@utils/browser"; import { RouteDataResponse } from "@utils/types"; import { Component } from "inferno"; import { @@ -36,7 +35,7 @@ export class Instances extends Component { super(props, context); // Only fetch the data if coming from another route - if (!isBrowser() || FirstLoadService.isFirstLoad) { + if (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 e8c707ed..722f6e70 100644 --- a/src/shared/components/modlog.tsx +++ b/src/shared/components/modlog.tsx @@ -5,7 +5,6 @@ import { personToChoice, setIsoData, } from "@utils/app"; -import { isBrowser } from "@utils/browser"; import { debounce, getIdFromString, @@ -661,7 +660,7 @@ export class Modlog extends Component< this.handleModChange = this.handleModChange.bind(this); // Only fetch the data if coming from another route - if (!isBrowser() || FirstLoadService.isFirstLoad) { + if (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 3c913701..395875be 100644 --- a/src/shared/components/person/inbox.tsx +++ b/src/shared/components/person/inbox.tsx @@ -11,7 +11,6 @@ import { setIsoData, updatePersonBlock, } from "@utils/app"; -import { isBrowser } from "@utils/browser"; import { RouteDataResponse } from "@utils/types"; import { Component, linkEvent } from "inferno"; import { @@ -164,7 +163,7 @@ export class Inbox extends Component { this.handleEditMessage = this.handleEditMessage.bind(this); // Only fetch the data if coming from another route - if (!isBrowser() || FirstLoadService.isFirstLoad) { + if (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 6e0530d9..d0003687 100644 --- a/src/shared/components/person/profile.tsx +++ b/src/shared/components/person/profile.tsx @@ -10,11 +10,7 @@ import { setIsoData, updatePersonBlock, } from "@utils/app"; -import { - isBrowser, - restoreScrollPosition, - saveScrollPosition, -} from "@utils/browser"; +import { restoreScrollPosition, saveScrollPosition } from "@utils/browser"; import { capitalizeFirstLetter, futureDaysToUnixTime, @@ -210,7 +206,7 @@ export class Profile extends Component< this.handleFeaturePost = this.handleFeaturePost.bind(this); // Only fetch the data if coming from another route - if (!isBrowser() || FirstLoadService.isFirstLoad) { + if (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 5e92c073..d9eb6ad0 100644 --- a/src/shared/components/person/registration-applications.tsx +++ b/src/shared/components/person/registration-applications.tsx @@ -3,7 +3,6 @@ import { myAuthRequired, setIsoData, } from "@utils/app"; -import { isBrowser } from "@utils/browser"; import { RouteDataResponse } from "@utils/types"; import { Component, linkEvent } from "inferno"; import { @@ -59,7 +58,7 @@ export class RegistrationApplications extends Component< this.handleApproveApplication = this.handleApproveApplication.bind(this); // Only fetch the data if coming from another route - if (!isBrowser() || FirstLoadService.isFirstLoad) { + if (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 9d04c8a7..8f5eaf36 100644 --- a/src/shared/components/person/reports.tsx +++ b/src/shared/components/person/reports.tsx @@ -5,7 +5,6 @@ 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"; @@ -109,7 +108,7 @@ export class Reports extends Component { this.handleResolvePrivateMessageReport.bind(this); // Only fetch the data if coming from another route - if (!isBrowser() || FirstLoadService.isFirstLoad) { + if (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 ed686f31..fe941830 100644 --- a/src/shared/components/post/create-post.tsx +++ b/src/shared/components/post/create-post.tsx @@ -1,5 +1,4 @@ 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"; @@ -70,7 +69,7 @@ export class CreatePost extends Component< this.handleSelectedCommunityChange.bind(this); // Only fetch the data if coming from another route - if (!isBrowser() || FirstLoadService.isFirstLoad) { + if (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 54823f22..f0aa3ff5 100644 --- a/src/shared/components/post/post.tsx +++ b/src/shared/components/post/post.tsx @@ -174,7 +174,7 @@ export class Post extends Component { this.state = { ...this.state, commentSectionRef: createRef() }; // Only fetch the data if coming from another route - if (!isBrowser() || FirstLoadService.isFirstLoad) { + if (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 89ed7598..8afd3488 100644 --- a/src/shared/components/private_message/create-private-message.tsx +++ b/src/shared/components/private_message/create-private-message.tsx @@ -1,5 +1,4 @@ import { getRecipientIdFromProps, myAuth, setIsoData } from "@utils/app"; -import { isBrowser } from "@utils/browser"; import { RouteDataResponse } from "@utils/types"; import { Component } from "inferno"; import { @@ -45,7 +44,7 @@ export class CreatePrivateMessage extends Component< this.handlePrivateMessageCreate.bind(this); // Only fetch the data if coming from another route - if (!isBrowser() || FirstLoadService.isFirstLoad) { + if (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 3d04c500..473b18c4 100644 --- a/src/shared/components/search.tsx +++ b/src/shared/components/search.tsx @@ -11,11 +11,7 @@ import { setIsoData, showLocal, } from "@utils/app"; -import { - isBrowser, - restoreScrollPosition, - saveScrollPosition, -} from "@utils/browser"; +import { restoreScrollPosition, saveScrollPosition } from "@utils/browser"; import { capitalizeFirstLetter, debounce, @@ -274,7 +270,7 @@ export class Search extends Component { }; // Only fetch the data if coming from another route - if (!isBrowser() || FirstLoadService.isFirstLoad) { + if (FirstLoadService.isFirstLoad) { const { communityResponse: communityRes, creatorDetailsResponse: creatorDetailsRes, diff --git a/src/shared/services/FirstLoadService.ts b/src/shared/services/FirstLoadService.ts index b7558eff..926e3acd 100644 --- a/src/shared/services/FirstLoadService.ts +++ b/src/shared/services/FirstLoadService.ts @@ -1,3 +1,5 @@ +import { isBrowser } from "@utils/browser"; + export class FirstLoadService { #isFirstLoad: boolean; static #instance: FirstLoadService; @@ -20,6 +22,6 @@ export class FirstLoadService { } static get isFirstLoad() { - return this.#Instance.isFirstLoad; + return !isBrowser() || this.#Instance.isFirstLoad; } } From 2f5933240084c309e634b6fd9158881f51f4d21a Mon Sep 17 00:00:00 2001 From: Dessalines Date: Fri, 23 Jun 2023 07:06:05 -0400 Subject: [PATCH 3/5] v0.18.0-rc.8 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index aaf623a6..b43a568b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lemmy-ui", - "version": "0.18.0-rc.7", + "version": "0.18.0-rc.8", "description": "An isomorphic UI for lemmy", "repository": "https://github.com/LemmyNet/lemmy-ui", "license": "AGPL-3.0", From 4a7bfe41d9ba053649fd57259fa9b8fba913ea41 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Fri, 23 Jun 2023 08:40:00 -0400 Subject: [PATCH 4/5] v0.18.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b43a568b..45d4daf1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lemmy-ui", - "version": "0.18.0-rc.8", + "version": "0.18.0", "description": "An isomorphic UI for lemmy", "repository": "https://github.com/LemmyNet/lemmy-ui", "license": "AGPL-3.0", From 955afeac3c084c0db9df426f6e960cf76c0bf2f4 Mon Sep 17 00:00:00 2001 From: dudeami0 Date: Fri, 23 Jun 2023 08:54:55 -0400 Subject: [PATCH 5/5] Fix homepage `scrollTo(0, 0)` failing when document size changes. --- src/shared/components/home/home.tsx | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/shared/components/home/home.tsx b/src/shared/components/home/home.tsx index bad771fc..71e5842e 100644 --- a/src/shared/components/home/home.tsx +++ b/src/shared/components/home/home.tsx @@ -101,6 +101,7 @@ interface HomeState { showTrendingMobile: boolean; showSidebarMobile: boolean; subscribedCollapsed: boolean; + scrolled: boolean; tagline?: string; siteRes: GetSiteResponse; finished: Map; @@ -217,6 +218,7 @@ export class Home extends Component { postsRes: { state: "empty" }, commentsRes: { state: "empty" }, trendingCommunitiesRes: { state: "empty" }, + scrolled: true, siteRes: this.isoData.site_res, showSubscribedMobile: false, showTrendingMobile: false, @@ -620,6 +622,11 @@ export class Home extends Component { search: getQueryString(queryParams), }); + if (!this.state.scrolled) { + this.setState({ scrolled: true }); + setTimeout(() => window.scrollTo(0, 0), 0); + } + await this.fetchData(); } @@ -815,23 +822,23 @@ export class Home extends Component { } handlePageChange(page: number) { + this.setState({ scrolled: false }); this.updateUrl({ page }); - window.scrollTo(0, 0); } handleSortChange(val: SortType) { + this.setState({ scrolled: false }); this.updateUrl({ sort: val, page: 1 }); - window.scrollTo(0, 0); } handleListingTypeChange(val: ListingType) { + this.setState({ scrolled: false }); this.updateUrl({ listingType: val, page: 1 }); - window.scrollTo(0, 0); } handleDataTypeChange(val: DataType) { + this.setState({ scrolled: false }); this.updateUrl({ dataType: val, page: 1 }); - window.scrollTo(0, 0); } async handleAddModToCommunity(form: AddModToCommunity) {