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: onboarding ready condition and missing deps #4153

Merged
merged 6 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/shared/src/hooks/auth/useOnboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const useOnboarding = (): UseOnboarding => {

return {
shouldShowAuthBanner,
isOnboardingReady: isActionsFetched && isAuthReady,
isOnboardingReady: isAuthReady && (isActionsFetched || !user),
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the issue here I missed it maybe?

Copy link
Member Author

@sshanzel sshanzel Feb 6, 2025

Choose a reason for hiding this comment

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

There is an edge case where the loading state is there endlessly. One of the conditions is whether the returned value here is not yet true. The loading never stop since anonymous user would not have actions hence not yet fetched.

Copy link
Member Author

Choose a reason for hiding this comment

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

Because of that, the event listeners are not rendered which is needed to process the callback page messages on login/sign up.

hasCompletedEditTags,
hasCompletedContentTypes,
completeStep: (action: ActionType) => completeAction(action),
Expand Down
29 changes: 21 additions & 8 deletions packages/webapp/pages/onboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ const seo: NextSeoProps = {
};

export function OnboardPage(): ReactElement {
const params = new URLSearchParams(window.location.search);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why move it and re-define it multiple places? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

So that it won't have to be a dependency on the memoized functions. Because if so, we will have to memoize this too since every render would create the object search param.

Also, they are used within those functions and not dependent on anything.

const { isAvailable: canUserInstallPWA } = useInstallPWA();
const {
isOnboardingReady,
Expand Down Expand Up @@ -225,31 +224,44 @@ export function OnboardPage(): ReactElement {
].includes(activeScreen);

useEffect(() => {
if (!isPageReady || isLogged.current || !isOnboardingReady) {
if (
!isPageReady ||
isLogged.current ||
!isOnboardingReady ||
!user?.infoConfirmed
) {
return;
}

if (user?.infoConfirmed && !hasCompletedEditTags) {
isLogged.current = true;

if (!hasCompletedEditTags) {
setActiveScreen(OnboardingStep.EditTag);
return;
}

if (user?.infoConfirmed && !hasCompletedContentTypes) {
if (!hasCompletedContentTypes) {
setActiveScreen(OnboardingStep.ContentTypes);
return;
}

if (user?.infoConfirmed && activeScreen === OnboardingStep.Intro) {
if (activeScreen === OnboardingStep.Intro) {
const params = new URLSearchParams(window.location.search);
const afterAuth = params.get(AFTER_AUTH_PARAM);
params.delete(AFTER_AUTH_PARAM);
router.replace(getPathnameWithQuery(afterAuth || webappUrl, params));
return;
}

isLogged.current = true;
// @NOTE see https://dailydotdev.atlassian.net/l/cp/dK9h1zoM
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isPageReady, user, isOnboardingReady]);
}, [
isPageReady,
user,
isOnboardingReady,
hasCompletedEditTags,
hasCompletedContentTypes,
activeScreen,
]);

const onClickNext: OnboardingOnClickNext = (options) => {
logEvent({
Expand Down Expand Up @@ -346,6 +358,7 @@ export function OnboardPage(): ReactElement {
: LogEvent.OnboardingSkip,
});

const params = new URLSearchParams(window.location.search);
const afterAuth = params.get(AFTER_AUTH_PARAM);
return router.replace({
pathname: afterAuth || '/',
Expand Down