Replies: 3 comments 6 replies
-
Thank you for your feedback @jangxyz it is very helpful ! Modules are actually super powerful and even Nuxt itself use modules in its core, so we shouldn't hit any hard limitations for a while. You are right, the implementations use regular nitro handlers and useFetch, but that can be changed as well.
|
Beta Was this translation helpful? Give feedback.
-
Here's a minimal reproduction on stackblitz: https://stackblitz.com/edit/nuxt-starter-trga3p?file=components%2FBooks.vue You can see the Some interesting points:
I'm also checking on the route params update as well. Stay tuned for feedbacks! :) |
Beta Was this translation helpful? Give feedback.
-
I also want to mention that @posva is working on vuejs/rfcs#460 , which could be a better underlying implementation than using a regular nitro handler. |
Beta Was this translation helpful? Give feedback.
-
Reading "Form actions for progressive enhancement" issue on nuxt/#20649, I understand the purpose of form actions. I'm still bit confused with server loaders though.
Coming from SvelteKit, I understand that both form actions and data loading on the server side are two critical channels of data communication between the client and the server.
In fact, I was a bit surprised to find out that nuxt did not have anything like it by default, and the closest thing was using
server/api/
. Guess how happy I was when I discovered this module 😂However, although form actions does meet the expectations of what I have thought of, server loaders still lacks some features. Since the nuxt issue above only discusses about form actions, I thought this would be a good place to ask about server loaders.
In sveltekit, the purpose of Loading data is to provide data required for page component to render on the server, which is accomplished without any additional fetch requests. From the components perspective, you receive the data as a prop, and no need to perform a fetch request.
From the PESPA article you've introduced (great article, by the way!)
PESPA Document Request
... Routing and Data fetching is solely done on server side.
This does not seem to be the case for Server Loaders, in which:
though it does render on the server, during hydration
useLoader()
performs additional fetch request via/_nitro/loader/
.plus, Vue warns about Hydration text mismatch. Scary 😨
the loader does not provide route matching, so defining a server loader in
server/actions/books/[bookId].ts
does not captureuseLoader('books/123')
. It only works when I call a literaluseLoader('books/[bookId]')
. Form actions are able to pass additional parameters via form data, but we don't have additional channels to pass params for server loaders.In SvelteKit using data loaders is the default way of passing data for SSR, and I was expecting something similar:
Thinking about these limitations, it seems like the current implementation is a wrapper around
/server/api/
, and by defining a server loader 1) it provides an api internally, and 2) requests the api on render.Though if this is the case, it is strange that while
/server/api/books/[bookId]
works,/server/actions/books/[bookId]
does not.Is this the limit of the current architecture of nuxt -- which I do not know deeply of -- and is the best so far a module can get? Or maybe there is no limits on the architecture, and the implementations are coming, and I just need to wait a bit longer?
My most fearful scenario would be that this is by design, and the server loader is not the same as sveltekit data loaders (which is hard to imagine, reading through the discussion in nuxt/#20649). If that is the case, I would have to go back and 'build an api endpoint' for every page components (sigh).
Beta Was this translation helpful? Give feedback.
All reactions