Surreal
Rollup error when using server components
I'm hitting a Rollup error when using server-only components, and I'm not sure how to best resolve it.
Essentially, I'm using the Nuxt 4-style folder structures and have a server-only component, /app/components/MyComponent.server.vue, which is importing some server-only code, /server/db/UserRepository (essentially some code to connect to my database and retrieve a user). This works fine locally in development, but is throwing a Rollup error when I go to build the code for production. I'm pretty sure that the error is because Rollup is trying to include server-only libraries (i.e., postgres, which uses Node.js modules like perf_hook, etc.) in the client-bundle, but I'm not clear why it would be trying to include code imported by a server component.
Is this a bug? A missing feature (i.e., don't try to bundle server component code in the browser bundle)? Any ideas how to workaround it? I'd rather not have to create an API endpoint for fetching this data, as it's not something I intend to expose externally.
7 replies
i18n and route rules
I'm using the latest version of Nuxt + @nuxtjs/i18n configured with strategy: 'prefix_except_default' and recently noticed something odd - my route rules aren't being applied to prefixed paths. For example, routeRules: { '/foobar': { ssr: false } } only applies to /foobar, not the prefixed /fr/foobar path. It's relatively easy to work around by adding unique route rules for every language, for every path, but it does quickly multiply the number of route rules which is annoying.
I was just wondering - does anyone happen to know if this has always worked this way, or if it may be a newish bug? I've been running Nuxt + i18n in production with a half dozen languages for at least a year, but this is the first time I noticed the route rules only applying to the default language's (non-prefixed) path.
5 replies
How to access buildId/build hash at runtime?
I've been trying to figure out how to access the build id/hash on the server side at runtime, so that I can build something from the client side to detect when a new version of my code has been released (e.g., expose the build hash via server API, periodically query it or build a websocket to monitor for change, etc.). Anyone know how to do this?
The only things I've been able to find in this vein require either (1) hardcoding the buildId via config, or (2) intercepting, overriding, and storing the default hash generation in the "build:before" lifecycle hook. I'm hoping there's just a simpler, out-of-the-box way to access the existing generated ID.
Thanks in advance!
3 replies
How to get cookie value in SSR page?
I'm probably missing something, but I'm not understanding why I can't access a cookie value from a server-side rendered page.
In a most basic sense, why doesn't {{ useCookie('foobar') }} show the value of that cookie in the server-side rendered HTML? It works correctly when the page is rendered client-side, and I can get the cookie value using getCookie() in a /server/api/ endpoint -- but I was under the assumption that useCookie is "SSR-friendly" and should be able to retrieve the cookie value for the server-rendered page?
6 replies