Skip to content

Commit

Permalink
fix: deffer state updates causing issues for google indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrumm committed Feb 7, 2024
1 parent 1c083a2 commit 9bee393
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
30 changes: 16 additions & 14 deletions src/hooks/config-loader.hook.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect } from 'react';
import { startTransition, useEffect } from 'react';

import { api } from 'fpp/utils/api';

Expand Down Expand Up @@ -28,18 +28,20 @@ export const useConfigLoader = () => {
});

useEffect(() => {
if (statusGetFeatureFlag === 'success') {
setFeatureFlags(featureFlags);
} else {
setFeatureFlags(
Object.keys(FeatureFlagType).map((name) => ({
name: name as keyof typeof FeatureFlagType,
enabled: false,
})),
);
}
if (statusGetLatestTag === 'success') {
setLatestTag(latestTag);
}
startTransition(() => {
if (statusGetFeatureFlag === 'success') {
setFeatureFlags(featureFlags);
} else {
setFeatureFlags(
Object.keys(FeatureFlagType).map((name) => ({
name: name as keyof typeof FeatureFlagType,
enabled: false,
})),
);
}
if (statusGetLatestTag === 'success') {
setLatestTag(latestTag);
}
});
}, [statusGetFeatureFlag, statusGetLatestTag]);
};
8 changes: 5 additions & 3 deletions src/hooks/use-tracking.hook.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useEffect } from 'react';
import { startTransition, useEffect } from 'react';

import { env } from 'fpp/env.mjs';

Expand Down Expand Up @@ -70,8 +70,10 @@ export const sendTrackPageView = ({
fetch(url, { body, method: 'POST', keepalive: true })
.then((res) => res.json() as Promise<{ userId: string }>)
.then(({ userId }) => {
setUserIdLocalStorage(userId);
setUserIdRoomState(userId);
startTransition(() => {
setUserIdLocalStorage(userId);
setUserIdRoomState(userId);
});
logger.debug(logEndpoint.TRACK_PAGE_VIEW, {
withBeacon: false,
});
Expand Down

0 comments on commit 9bee393

Please sign in to comment.