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 server-side rendering after first load. #1509

Merged
merged 2 commits into from
Jun 23, 2023

Conversation

dudeami0
Copy link
Contributor

Server-side rendering was being disabled by the global variable FirstLoadService.isFirstLoad being set on the server side to false after the first page was rendered. This commit adds a check for if !isBrowser() so server side rendering is triggered on every page request. This was preventing Open Graph meta tags and other metadata from being generated.

@@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If everywhere isFirstLoad is used needs to be ORed with !isBrowser(), it's easier to move that logic to the isFirstLoad function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hesitant to change the functionality of isFirstLoad in the case it was used for server initialization. If isFirstLoad is assumed to be browser first load I'll move the check there.

@SleeplessOne1917 SleeplessOne1917 merged commit 9040e2f into LemmyNet:main Jun 23, 2023
@dudeami0 dudeami0 deleted the fix/ssr-isFirstLoad branch June 23, 2023 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants