Migrate pages from Page.getInitialProps
to getServerSideProps
#2957
Conversation
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.
Awesome! This kind of consistency and better types will hopefully make it easier to avoid bugs, and for folks to know the "right way" to do things
e2d5c95
to
1ec1c8a
Compare
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 there could be some speed efficiencies by combining async requests in the getServerSideProps
call, but that might be worth ticketing versus doing that work here.
appContext.query; | ||
const { groups } = await client.request("get", `/groups`); | ||
const { id, limit, offset, state, recordId, destinationId } = ctx.query; | ||
const { groups } = await client.request<Actions.GroupsList>("get", `/groups`); | ||
|
||
let exportProcessorId: string; |
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.
Nitpick, though I know this was around before:
let exportProcessorId: string; | |
let exportProcessorId = ""; |
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.
Will leave as is because it was like that before. I'm not sure if this will cause the action to fail later on, and I'd like not to specifically test this.
@@ -428,7 +428,7 @@ RecordsList.hydrate = async ( | |||
caseSensitive, | |||
} = ctx.query; | |||
|
|||
const { records, total }: Actions.RecordsList = await client.request( | |||
const { records, total } = await client.request<Actions.RecordsList>( |
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.
👍
let scheduleRuns = []; | ||
let schedules = []; | ||
|
||
if (sources) { | ||
schedules = sources | ||
.filter( | ||
(source) => source.appId === app.id && source.schedule?.refreshEnabled | ||
) | ||
.map((source) => source.schedule); |
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.
Nitpick, and I'm not sure if this is more efficient.
let scheduleRuns = []; | |
let schedules = []; | |
if (sources) { | |
schedules = sources | |
.filter( | |
(source) => source.appId === app.id && source.schedule?.refreshEnabled | |
) | |
.map((source) => source.schedule); | |
const scheduleRuns = []; | |
const schedules = []; | |
if (sources) { | |
schedules.push(...sources | |
.filter( | |
(source) => source.appId === app.id && source.schedule?.refreshEnabled | |
) | |
.map((source) => source.schedule)); |
|
||
plugins = plugins | ||
.filter((p) => p.apps?.length > 0) | ||
.sort((a, b) => (a.name > b.name ? 1 : -1)); |
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.
.sort((a, b) => (a.name > b.name ? 1 : -1)); | |
.sort((a, b) => (a.name > b.name ? 1 : a.name < b.name ? -1 : 0)); |
); | ||
ensureMatchingModel("Source", source.modelId, modelId.toString()); | ||
|
||
const runsListInitialProps = await RunsList.hydrate(ctx, { topic: "source" }); |
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 probably worth putting what RunsList.hydrate
does into another method and calling that method from both places, rather than doing it like it.
@krishnaglick I appreciate all the suggestions but I wanted to focus this on migrating from one function to another without making a lot of changes unless it was necessary (like that groups rules file). I rather not apply these changes since every I apply I should re-test. |
I feel like these two should be addressed: Everything else can be ticketed or counted as a nitpick I'd say. |
ff71fa3
to
90fef65
Compare
* Update migrated pages to infer props from getServerSideProps * Ensure all types are assigned to props returned from getServerSideProps * Fix typing and mutation issues in groups/rules page rendering * Update export list hydration url match from appContext.pathname to ctx.req.url to be compatible with server side props
90fef65
to
f83bccd
Compare
Rebased and address @krishnaglick's comments. |
Change description
This updates all UI pages to use
getServerSideProps
overgetInitialProps
as it's the newest recommended way to use Next: https://nextjs.org/docs/api-reference/data-fetching/get-initial-propsThe only caveat is that you have to ensure that
getServerSideProps
is exported on the apps that consumeui-components
:The only exceptions are
_app.tsx
and_error.tsx
. These still usegetInitialProps
becausegetServerSideProps
is not supported as of now:https://nextjs.org/docs/advanced-features/custom-app#caveats
https://nextjs.org/docs/advanced-features/custom-error-page#caveats
It also ensures that all the props coming from getServerSideProps are typed.
Also fixes a few typing issues along the way as the files were being migrated, most notably the
groups/rules.tsx
page.Checklists
Development
Impact
Please explain any security, performance, migration, or other impacts if relevant:
Code review