How to resolve the increased cost of web server caused by server action ? #65523
Unanswered
relax-code-relax-life
asked this question in
Help
Replies: 1 comment 1 reply
-
You could abstract // getList.ts
// "shared" module - can be imported from both a client and a server component
export async function getList({ token }) {
return (await fetch(/* ..... */)).json()
} In the server component: import {getList} from './get-list'
export async default function() {
const token = cookies().get('token').value
const list = await getList({token});
// render
} and in a client component: "use client";
import {getList} from './get-list'
export default function({initialList}) {
// .... same as before ...
// access cookies via `document.cookie` or a wrapping API, pass to `getList`
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Summary
I am using the App router + server action of Next v14. I have a page, running in mobile browser, that render a product list and support infinite scroll load.
There are 3 main files.
Now, it is make sense that the first request to backend by SSR is from my web server.
But, the subsequent request triggered by scroll-load will first go from the user mobile to my web server, and then from my web server to backend, which is unreasonable.
Because this increases the pressure on my web server, the subsequent requests should be directly requested to the backend.
But if I write another client fetch function, I will do not reuse the
getList
function ofaction
. And I will have wrote two functions for the same logic, I think it's also unreasonable.So, is there a good solution that can handle this situation, where the first SSR rendering uses server fetch, but then uses client fetch ?
Additional information
No response
Example
No response
Beta Was this translation helpful? Give feedback.
All reactions