Conversation
Jetpack Cloud live (direct link)
Automattic for Agencies live (direct link)
|
There was a problem hiding this comment.
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() );
|
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(); |
There was a problem hiding this comment.
| const [ , setSearchParams ] = useSearchParams(); | |
| const [ setSearchParams ] = useSearchParams(); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@zaerl Do you mean to say the current version is correct or the suggestion version is?
There was a problem hiding this comment.
@zaerl Do you mean to say the current version is correct or the suggestion version is?
The current one is right.
| url.searchParams.set( 'playground', playgroundId ); | ||
| window.history.replaceState( {}, '', url.toString() ); |
There was a problem hiding this comment.
setSearchParams updates the navigation, so we don't need these lines anymore.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
No, I tried it locally and it worked for me, but if you have the issue let's leave it as-is.
There was a problem hiding this comment.
I don't have experience with react-router-dom, but from reading their docs it sounded like the navigation should be updated.
There was a problem hiding this comment.
@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.
|
This PR modifies the release build for the following Calypso Apps: For info about this notification, see here: PCYsg-OT6-p2
To test WordPress.com changes, run |
zaerl
left a comment
There was a problem hiding this comment.
Working as expected. Good job here.
|
@bgrgicak Gonna land this, but feel free to comment further and I can address in follow up PR, if needed. |
Related to #101948
Proposed Changes
Testing Instructions
http://calypso.localhost:3000/setup/onboarding/user?playground=xxxEnsure playground GET param is not missing from url
Pre-merge Checklist