Skip to content

Playground onboarding flow: update url via react router so next step can pick up playground GET param correctly#102037

Merged
ashfame merged 1 commit intotrunkfrom
fix/playground-onboarding-flow/101948
Mar 28, 2025
Merged

Playground onboarding flow: update url via react router so next step can pick up playground GET param correctly#102037
ashfame merged 1 commit intotrunkfrom
fix/playground-onboarding-flow/101948

Conversation

@ashfame
Copy link
Member

@ashfame ashfame commented Mar 28, 2025

Related to #101948

Proposed Changes

  • update search params through react router for next step to pick GET param accurately

Testing Instructions

Ensure playground GET param is not missing from url

Pre-merge Checklist

  • Has the general commit checklist been followed? (PCYsg-hS-p2)
  • Have you written new tests for your changes?
  • Have you tested the feature in Simple (P9HQHe-k8-p2), Atomic (P9HQHe-jW-p2), and self-hosted Jetpack sites (PCYsg-g6b-p2)?
  • Have you checked for TypeScript, React or other console errors?
  • Have you used memoizing on expensive computations? More info in Memoizing with create-selector and Using memoizing selectors and Our Approach to Data
  • Have we added the "[Status] String Freeze" label as soon as any new strings were ready for translation (p4TIVU-5Jq-p2)?
    • For UI changes, have we tested the change in various languages (for example, ES, PT, FR, or DE)? The length of text and words vary significantly between languages.
  • For changes affecting Jetpack: Have we added the "[Status] Needs Privacy Updates" label if this pull request changes what data or activity we track or use (p4TIVU-aUh-p2)?

@ashfame ashfame requested review from bgrgicak, Copilot and zaerl March 28, 2025 11:33
@ashfame ashfame self-assigned this Mar 28, 2025
@matticbot matticbot added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Mar 28, 2025
@github-actions
Copy link

github-actions bot commented Mar 28, 2025

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the playground onboarding flow so that the playground GET parameter is accurately propagated via React Router for subsequent steps.

  • Added a new setSearchParams callback parameter to update URL search parameters through React Router.
  • Updated the initializeWordPressPlayground function to call setSearchParams and modified the PlaygroundIframe component to pass the new callback.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
client/landing/stepper/declarative-flow/internals/steps-repository/playground/lib/initialize-playground.ts Added setSearchParams parameter and updated URL search params via both window.history.replaceState and the React Router method.
client/landing/stepper/declarative-flow/internals/steps-repository/playground/components/playground-iframe/index.tsx Imported and passed setSearchParams from useSearchParams to initializeWordPressPlayground.
Comments suppressed due to low confidence (2)

client/landing/stepper/declarative-flow/internals/steps-repository/playground/lib/initialize-playground.ts:27

  • Mutating the existing URLSearchParams object may not trigger a re-render; consider returning a new URLSearchParams instance (e.g., new URLSearchParams(prev) with the updated value) to ensure React Router properly detects the change.
setSearchParams( ( prev ) => { prev.set( 'playground', playgroundId as string ); return prev; } );

client/landing/stepper/declarative-flow/internals/steps-repository/playground/lib/initialize-playground.ts:24

  • Using both window.history.replaceState and setSearchParams to update the URL may lead to redundant or conflicting state updates; consider consolidating URL updates to use React Router exclusively if possible.
window.history.replaceState( {}, '', url.toString() );

@matticbot
Copy link
Contributor

This PR does not affect the size of JS and CSS bundles shipped to the user's browser.

Generated by performance advisor bot at iscalypsofastyet.com.

} ) {
const iframeRef = useRef< HTMLIFrameElement >( null );
const recommendedPHPVersion = usePhpVersions().recommendedValue;
const [ , setSearchParams ] = useSearchParams();
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const [ , setSearchParams ] = useSearchParams();
const [ setSearchParams ] = useSearchParams();

Copy link
Member Author

Choose a reason for hiding this comment

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

Don't think this is correct. We need to skip the first returned value and assign second returned value to the const. Can you explain?

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't think this is correct. We need to skip the first returned value and assign second returned value to the const. Can you explain?

Yes, it's the current version. We only need the set function.

Copy link
Member Author

Choose a reason for hiding this comment

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

@zaerl Do you mean to say the current version is correct or the suggestion version is?

Copy link
Contributor

Choose a reason for hiding this comment

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

@zaerl Do you mean to say the current version is correct or the suggestion version is?

The current one is right.

Comment on lines 24 to 25
url.searchParams.set( 'playground', playgroundId );
window.history.replaceState( {}, '', url.toString() );
Copy link
Contributor

Choose a reason for hiding this comment

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

setSearchParams updates the navigation, so we don't need these lines anymore.

Copy link
Member Author

Choose a reason for hiding this comment

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

I actually removed them first but browser history state wasn't updated so had to add them back again. Know what might be going on?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I tried it locally and it worked for me, but if you have the issue let's leave it as-is.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't have experience with react-router-dom, but from reading their docs it sounded like the navigation should be updated.

Copy link
Member Author

Choose a reason for hiding this comment

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

@bgrgicak Just to confirm how I tested this: Without these lines, if I am going back by the browser's back button, I get to http://calypso.localhost:3000/setup/onboarding/playground?playground=9a566c25-a356-4b43-8438-ccfc6fc3cbf0 and then http://calypso.localhost:3000/setup/onboarding/playground so history state wasn't replaced.

@matticbot
Copy link
Contributor

This PR modifies the release build for the following Calypso Apps:

For info about this notification, see here: PCYsg-OT6-p2

  • blaze-dashboard
  • help-center
  • notifications
  • wpcom-block-editor

To test WordPress.com changes, run install-plugin.sh $pluginSlug fix/playground-onboarding-flow/101948 on your sandbox.

Copy link
Contributor

@zaerl zaerl left a comment

Choose a reason for hiding this comment

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

Working as expected. Good job here.

@ashfame
Copy link
Member Author

ashfame commented Mar 28, 2025

@bgrgicak Gonna land this, but feel free to comment further and I can address in follow up PR, if needed.

@ashfame ashfame merged commit 79dbd3e into trunk Mar 28, 2025
18 checks passed
@ashfame ashfame deleted the fix/playground-onboarding-flow/101948 branch March 28, 2025 12:39
@github-actions github-actions bot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Mar 28, 2025
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.

4 participants

Comments