Slow server actions blocking dynamic imports and other server actions.
Unanswered
Brown bear posted this in #help-forum
Brown bearOP
Let's say you have some dynamic imports and other server actions running on the client side during on load.
Try this:
All other server actions and dynamic imports will be blocked until this slow server action is completed. Does anyone have this problem? Switching this function to client side will disable the blocking effect.
Try this:
'use server'; // Server action
export default async function getSlow() {
await new Promise((resolve) => setTimeout(resolve, 10000));
return true;
}// In some page..
useEffect(() => {
(async () => {
await getSlow();
})();
}, []);All other server actions and dynamic imports will be blocked until this slow server action is completed. Does anyone have this problem? Switching this function to client side will disable the blocking effect.
3 Replies
@Brown bear Let's say you have some dynamic imports and other server actions running on the client side during on load.
Try this:
'use server'; // Server action
export default async function getSlow() {
await new Promise((resolve) => setTimeout(resolve, 10000));
return true;
}
// In some page..
useEffect(() => {
(async () => {
await getSlow();
})();
}, []);
All other server actions and dynamic imports will be blocked until this slow server action is completed. Does anyone have this problem? Switching this function to client side will disable the blocking effect.
Yes, server actions cannot be run in parallel. That is one of several reasons it’s not recommended to perform data fetching with server actions like you did.
@joulev Yes, server actions cannot be run in parallel. That is one of several reasons it’s not recommended to perform data fetching with server actions like you did.
Brown bearOP
you mean don't use it on useEffect, or like on loading time
@Brown bear you mean don't use it on useEffect, or like on loading time
Yes. Only use server actions for mutations triggered by a client side interaction, like a form submission or a button click