-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Odyssey Stats: Fix redirection with query string for custom date range #97658
Odyssey Stats: Fix redirection with query string for custom date range #97658
Conversation
Jetpack Cloud live (direct link)
Automattic for Agencies live (direct link)
|
Here is how your PR affects size of JS and CSS bundles shipped to the user's browser: Sections (~4 bytes removed 📉 [gzipped])
Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to. Async-loaded Components (~35 bytes added 📈 [gzipped])
React components that are loaded lazily, when a certain part of UI is displayed for the first time. Legend What is parsed and gzip size?Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory. Generated by performance advisor bot at iscalypsofastyet.com. |
client/my-sites/stats/site.jsx
Outdated
@@ -918,7 +926,8 @@ export default connect( | |||
supportUserFeedback, | |||
} = getEnvStatsFeatureSupportChecks( state, siteId ); | |||
|
|||
const hasSiteLoadedFeatures = hasLoadedSiteFeatures( state, siteId ); | |||
// Odyssey Stats does not need loading features to determine gated features. | |||
const hasSiteLoadedFeatures = hasLoadedSiteFeatures( state, siteId ) || isOdyssey; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const hasSiteLoadedFeatures = hasLoadedSiteFeatures( state, siteId ) || isOdyssey; | |
const hasSiteLoadedFeatures = isOdyssey || hasLoadedSiteFeatures( state, siteId ); |
If we swap these conditions, we'll avoid calling the function at all inside Odyssey.
client/my-sites/stats/site.jsx
Outdated
@@ -326,6 +326,7 @@ class StatsSite extends Component { | |||
isJetpack, | |||
isSitePrivate, | |||
isOdysseyStats, | |||
isOdyssey, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit confusing having both isOdyssey
and isOdysseyStats
here. Is this the case where one represents API routing vs direct calls to wpcom? If so, we should probably rename it now to avoid confusion.
Update: I see two more instances of this below confirming the above comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If so, we should probably rename it now to avoid confusion.
I think so. That would be the refactoring work, as we will tackle them all at once later. Context: p1733887222490759-slack-C82FZ5T4G.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, maybe isWPAdmin
a better name for isOdyssey
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in c0df942.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't quite work correctly in my testing. I'm seeing that in some cases, the page=stats
is added to the params twice. Then, if the user refreshes the page, the browser tries to encode the parameter list. I end up seeing the following:
?page%5B0%5D=stats&page%5B1%5D=stats&chartStart=2024-12-20&chartEnd=2024-12-20
That decodes to:
?page[0]=stats&page[1]=stats
So it appears the browser is trying to number the duplicate params?
I think the fix is probably to dedupe the params before updating the string maybe?
const queryString = isOdyssey && query ? `&${ new URLSearchParams( query ).toString() }` : ''; | ||
|
||
return `${ baseUrl }${ queryString }`; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested the following and it's working in my testing.
export const parseQueryStringForOdysseyRedirect = ( baseUrl, isOdyssey, query = {} ) => {
const newParams = new URLSearchParams( window.location.search );
if ( isOdyssey ) {
const queryParams = new URLSearchParams( query );
queryParams.forEach( ( value, key ) => {
newParams.set( key, value );
} );
}
return `${ baseUrl }?${ newParams.toString() }`;
};
We'd then need to upate the two call sites to not include window.location.search
in the base URL value.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not prefer to make the function process inputs along with a global variable simultaneously, which would make it quite MAGIC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw it when testing, but reproducing it was not easy. Could you provide a way to reproduce it constantly? |
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 |
client/my-sites/stats/controller.jsx
Outdated
isWpAdmin && context.query ? `&${ new URLSearchParams( context.query ).toString() }` : ''; | ||
const url = `/stats/day/${ context.params.module }/${ context.params.site }${ window.location.search }${ query }`; | ||
const url = parseQueryStringForOdysseyRedirect( | ||
`/stats/day/${ context.params.module }/${ context.params.site }${ window.location.search }`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might not need ${ window.location.search }
here, which probably caused the issue of multiple page=stats
issue.
I think we could use query
, path
and/or pathname
from context
, which are unified in both Odyssey and Calypso, which apparently I missed when adding the redirection logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems we only need the base pathname and append the context.query
params string to it, which works on both Caylpso and Odyssey Stats. Updated in 0fc48b5.
So I tested this again today. It's very easy to reproduce for me. The steps are:
The actual full URL I'm seeing is this:
So |
I updated the URL path processor to use the base pathname and append the query string from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works well and looks good 👍
Follow-up of fixing redirection on Odyssey Stats from #97591.
Proposed Changes
appendQueryStringForRedirection
function to append the query string for redirection on Odyssey Stats.Why are these changes being made?
context.query
rather thanwindow.location.search
for Odyssey Stats. So, the redirection that happens on Odyssey Stats may need an extra query object parsing process.Testing Instructions
cd /some-path-to/wp-calypso/apps/odyssey-stats && STATS_PACKAGE_PATH=/some-path-to/jetpack/projects/packages/stats-admin yarn dev
.Yesterday
shortcut.Before the change
2024-12-20.12.52.00.mov
After the change
2024-12-20.12.55.13.mov
Weeks
and a date range shortcut other than the defaultLast 7 Days
.2024-12-20.12.59.54.mov
Pre-merge Checklist