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

Stepper: ignore ref changes when customizing calypso_signup_start #98235

Merged
merged 2 commits into from
Jan 10, 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
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useEffect } from 'react';
import { useSearchParams } from 'react-router-dom';
import { STEPPER_TRACKS_EVENT_SIGNUP_START } from 'calypso/landing/stepper/constants';
import recordSignupStart from 'calypso/landing/stepper/declarative-flow/internals/analytics/record-signup-start';
import useSnakeCasedKeys from 'calypso/landing/stepper/utils/use-snake-cased-keys';
Expand All @@ -16,8 +15,6 @@ interface Props {
}

export const useSignUpStartTracking = ( { flow }: Props ) => {
const [ queryParams ] = useSearchParams();
const ref = queryParams.get( 'ref' ) || '';
const flowName = flow.name;
const flowVariant = flow.variantSlug;
const isSignupFlow = flow.isSignupFlow;
Expand Down Expand Up @@ -50,6 +47,9 @@ export const useSignUpStartTracking = ( { flow }: Props ) => {
return;
}

// Read the ref here to avoid re-rendering the hook when it changes.
const ref = new URLSearchParams( window.location.search ).get( 'ref' ) || '';

recordSignupStart( {
flow: flowName,
ref,
Expand All @@ -58,5 +58,5 @@ export const useSignUpStartTracking = ( { flow }: Props ) => {
...( flowVariant && { flow_variant: flowVariant } ),
},
} );
}, [ isSignupFlow, flowName, ref, signupStartEventProps, isLoading, flowVariant ] );
}, [ isSignupFlow, flowName, signupStartEventProps, isLoading, flowVariant ] );
};
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@ const render = ( { flow, queryParams = {} } ) => {
flow,
} ),
{
wrapper: ( { children } ) => (
<MemoryRouter initialEntries={ [ addQueryArgs( `/setup/${ flow.name }`, queryParams ) ] }>
{ children }
</MemoryRouter>
),
wrapper: ( { children } ) => {
// The hook depends on window.location.search to determine the query params.
Reflect.deleteProperty( global.window, 'location' );
window.location = new URL(
'https://example.com/' + addQueryArgs( `/setup/${ flow.name }`, queryParams )
) as unknown as Location;
return <MemoryRouter initialEntries={ [ '/setup' ] }>{ children }</MemoryRouter>;
},
}
);
};
Expand Down
Loading