-
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
Site Migration: Enable to manage when the site migration key will be loaded #90086
Conversation
Jetpack Cloud live (direct link)
Automattic for Agencies live (direct link)
|
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. |
export const useSiteMigrationKey = ( siteId?: number ) => { | ||
type Options = Pick< UseQueryOptions, 'enabled' >; | ||
|
||
export const useSiteMigrationKey = ( siteId?: number, options?: Options ) => { |
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 think it's confusing for the Options
type to be UseQueryOptions
. Looking at this hook from another programmer POV, I would expect to configure the whole query via this options
parameter given it's type (like queryKey, queryFn, etc), but I can only affect retry
and enabled
in some special circumstances.
Since it looks like it will only be used to control retry & enabled I think a custom type for only those two things would be more clear.
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 am not sure if I understood.
In this case, I'm just reusing the enabled type definition instead of being an "UseQueryOption type".
Are you suggesting something like:
interface Options {
enabled: boolean?
}
Or are you suggesting open to receiving all useQueryOption attributes?
Using the Pick
we can't pass all other attributes.
The idea is not to enable configuring the other parts because it is not generic and it can break the usage.
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.
Maybe I didn't explain myself correctly. Basically I don't see the value of picking from the UseQueryOption
type since it is not going to affect the query directly, making the semantics slightly different.
Say you have the following code:
useSiteMigrationKey( null, { enabled: true } )
I would expect for the actual API call to be made, because I enabled it and it's a UseQueryOption pick, so it would be reasonable to override default behaviour. But it is not made because siteId is null.
If we had a custom type for this hook, say something like:
interface Options {
stalling: boolean?
}
This purpose of this call useSiteMigrationKey( null, { stalling: true } )
would be clearer to me, because I wouldn't have an expectation about the inner implementation.
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 gotcha, you won't to create false expectations by saying this enabled
will not work exactly in a similar way to the original one.
I have mixed feelings, so I would like to think more.
Do you mind if I create a separate issue just to give me more time to think about it and not block it?
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 gotcha, you won't to create false expectations by saying this enabled will not work exactly in a similar way to the original one.
In my mind, the expectation is created by the enabled
being picked from UseQueryOption
not from it being called enabled
.
Do you mind if I create a separate issue just to give me more time to think about it and not block it?
yup, go ahead! I'll approve all of this
Part of #89760
Proposed Changes
It is part of #89760 where we need to control a sequence of requests to ensure a site is ready to run the migrate-guru migration.
I am going to use this feature in further PRs.
enable
prop on the use-site-migration-key hook to manage when we want to start fetching the key.Testing Instructions