-
Notifications
You must be signed in to change notification settings - Fork 9.3k
perf: fetch server side data for workflow details page #20778
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
base: main
Are you sure you want to change the base?
perf: fetch server side data for workflow details page #20778
Conversation
@TusharBhatt1 is attempting to deploy a commit to the cal Team on Vercel. A member of the Team first needs to authorize it. |
Hey there and thank you for opening this pull request! 👋🏼 We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted. Details:
|
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.
mrge found 3 issues across 5 files. View them in mrge.io
Graphite Automations"Add consumer team as reviewer" took an action on this PR • (04/20/25)1 reviewer was added to this PR based on Keith Williams's automation. "Add community label" took an action on this PR • (04/20/25)1 label was added to this PR based on Keith Williams's automation. |
teamId: workflow?.team?.id, | ||
}, | ||
{ enabled: !verifiedEmailsProp } | ||
); |
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.
Moved to server side
…https://github.com/TusharBhatt1/cal.com into perf/fetch-server-side-data-for-dynamic-webflow-page
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.
Great job Tushar! That was fast. But this requires some changes.
if (!workflowData) return notFound(); | ||
|
||
const isOrg = workflowData?.team?.isOrganization ?? false; | ||
const teamId = workflowData?.teamId ?? undefined; |
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.
Q: what happens when teamId
is undefined? does it break anything? if so, shouldn't we show 404 page?
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.
In that case it returns [] - empty array
same as what we have as fallback rn , nothing's breaking
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 can improve it by skipping the verifiedNumbers call if teamId is undefined and return [] straight away
@@ -34,7 +34,7 @@ function UsersTable({ setSMSLockState }: Props) { | |||
const { data: usersAndTeams } = trpc.viewer.admin.getSMSLockStateTeamsUsers.useQuery(); | |||
|
|||
if (!usersAndTeams) { | |||
return <></>; | |||
return null; |
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.
can you explain why this change was necessary?
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.
Just for better readability/code quality
const [isPhoneNumberNeeded, setIsPhoneNumberNeeded] = useState(false); | ||
const [isSenderIdNeeded, setIsSenderIdNeeded] = useState(false); | ||
const [isEmailAddressNeeded, setIsEmailAddressNeeded] = useState(false); | ||
const { data: actionOptions } = trpc.viewer.workflows.getWorkflowActionOptions.useQuery(); |
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 query should stay client-side because the "Add action" Dialog should not block the initial load. For example, imagine that the query fetching for Add Action Dialog failed. Now it blocks the entire page load. Handling a query failure is another topic, but I am mentioning it to help you decide which is something you should fetch server-side vs client-side. The more server-side fetching we do, the slower the initial load is, and hence we should determine carefully which queries to turn to server-side and keep client-side.
So, Please think about this for other queries you switched to server-side in this PR and make changes accordingly!

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.
So basically we where doing this same call two times : one for the page (form)
and another for this Dialog
so I just removed it from here and passed from the page - I understand your concerns but that's not the case here
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 don't think you understood my point. I am saying we should not have workflowCaller.getWorkflowActionOptions()
in RSC.
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.
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.
You can simply let const { data: actionOptions } = trpc.viewer.workflows.getWorkflowActionOptions.useQuery();
just stay in packages/features/ee/workflows/components/AddActionDialog.tsx
unless you have a better optimization in mind.
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.
You can simply let const { data: actionOptions } = trpc.viewer.workflows.getWorkflowActionOptions.useQuery(); just stay in packages/features/ee/workflows/components/AddActionDialog.tsx unless you have a better optimization in mind.
Then we'll end up doing two calls for actionOptions as soon as the page renders (current behaviour on prod) - one in WorkflowDetailsPage.tsx
and another in AddActionDialog.tsx
(we require this data on both places)
I have updated it to call just once just inside WorkflowDetailsPage
and simply pass it to AddActionDialog
as prop
Thoughts ?
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.
That sounds good but is it necessary? Client-side trpc queries are cached, no? especially since these two queries happen almost at the same time?
I love to avoid prop drilling as much as possible unless it's necessary
Would be great to have you test this quickly 🙏
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.
The API calls increases making them look lot more - having one looked clean to me , anyways I have added an trpc call in the Dialog as well
E2E results are ready! |
Thanks @hbjORbj , I have addresed them all - can you have a look |
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.
mrge found 3 issues across 7 files. View them in mrge.io
} | ||
}, [isPending]); | ||
setFormData(workflow); | ||
}, []); |
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.
Empty dependency array in useEffect where workflow dependency is used
// teamId: workflow?.team?.id, | ||
// }); | ||
// } catch (err) {} | ||
const [verifiedEmails, verifiedNumbers, eventsData, user, actionOptions] = await Promise.all([ |
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.
Using index-based destructuring from Promise.all results can be error-prone if the order of promises changes in the future.
// teamId: workflow?.team?.id, | ||
// }); | ||
// } catch (err) {} | ||
const [verifiedEmails, verifiedNumbers, eventsData, user, actionOptions] = await Promise.all([ |
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.
Missing error handling for Promise.all. If any of these async calls fail, the entire page will fail.
@TusharBhatt1 Please review my comments more carefully and only ping me after more careful review of your code yourself. As I mentioned before, let's minimize the number of ping pongs as much as possible. Don't wanna spend 7-8 ping-pongs on a small change like the last time. |
…https://github.com/TusharBhatt1/cal.com into perf/fetch-server-side-data-for-dynamic-webflow-page
What does this PR do?
This PR moves all the
/workflows/[id]
data fetching to server side.Visual Demo (For contributors especially)
Before :


After:
dynamic-worklflows.mp4
Mandatory Tasks (DO NOT REMOVE)
Summary by mrge
Moved all data fetching for the
/workflows/[id]
page to the server side to improve performance and reliability.