strange runtimeConfig behaviour when prerendering parts of the app
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 60.9k
- Forks
- 5.8k
- Avg merge
- 7h 8m
- Merged PRs (30d)
- 162
Description
Environment
- Operating System: Linux
- Node Version: v20.11.0
- Nuxt Version: 3.11.2
- CLI Version: 3.11.1
- Nitro Version: 2.9.6
- Package Manager: pnpm@9.1.4
- Builder: -
- User Config: modules, experimental, ssr, css, colorMode, nitro, app, pwa, devtools, eslintConfig, i18n, vite, runtimeConfig
- Runtime Modules: @vueuse/nuxt@10.10.0, @unocss/nuxt@0.58.9, @pinia/nuxt@0.5.1, @pinia-plugin-persistedstate/nuxt@1.2.0, @nuxtjs/color-mode@3.4.1, @vite-pwa/nuxt@0.4.0, @bg-dev/nuxt-naiveui@1.10.1, @nuxtjs/i18n@8.3.1, unplugin-icons/nuxt, nuxt-module-eslint-config@0.1.1
- Build Modules: -
Reproduction
Nuxt Config:
export default defineNuxtConfig({
// ...
runtimeConfig: {
public: {
test: 'prerendered "test value" (default)',
onlyRuntime: 'prerendered "only runtime value" (default)'
},
},
nitro: {
esbuild: {
options: {
target: 'esnext',
},
},
prerender: {
crawlLinks: false,
routes: ['/'],
},
},
// ...
})
pages/index.vue
<template>
<div>
<h1>This Page is prerendered</h1>
{{config.public.test}} <br>
<NuxtLink to="/test">SSR page</NuxtLink>
</div>
</template>
<script setup lang="ts">
const config = useRuntimeConfig()
</script>
pages/test.vue
<template>
<div>
<h1>This Page is not prerendered</h1>
{{config.public.test}}<br>
{{config.public.onlyRuntime}}<br>
<NuxtLink to="/">prerendered Page</NuxtLink>
</div>
</template>
<script setup lang="ts">
const config = useRuntimeConfig()
</script>
env for node .output/server/index.mjs
environment:
- NUXT_PUBLIC_TEST=runtime "test value"
- NUXT_PUBLIC_ONLY_RUNTIME=runtime "only runtime value"
link to deployed version: https://app.runtime-config-example.v2.singular-it-test.de/
Describe the bug
Steps:
- open https://app.runtime-config-example.v2.singular-it-test.de/
- see varaibles
- navigate to SSR page
- variables are still from builttime
- refresh page
- variables are now from runtime
- navigate back to prerendered
- variables are still runtime
Additional context
i think it will be intended that way, but i find the behavior of the runtimeConfig sometimes a bit inconsistent, especially if you prerender parts of the app and others not. (and thus also with regard to the caching of pwa). Depending on the entry point in the app (i.e. whether generated or dynamic), this can lead to different configs, which then persist between the dynamic and static pages.
i don't expect prerendered parts of the app to pick up the runtime config, but i would assume that when i switch from a static to a non-static page, the runtime variables also play a role. Otherwise, as soon as prerender is active, everything should be set at build time (so that there can no longer be a runtime config) and everything is/needs to be set in the build step to avoid differences depending on the entry point.
I know that it is not necessarily common to have a different config for generation than for runtime, but especially in my case it is not necessary to set all variables in the build (prerender). and generally the runtime config is also there to set the variables when running the app.
Logs
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the supplied reproduction with pages/index.vue and pages/test.vue, using the shown runtimeConfig and nitro.prerender settings. Compare values during prerendered navigation, SSR navigation, and refreshes against the deployed example. Done means the expected runtimeConfig behavior across static and dynamic pages is agreed and covered by a regression test or clear documentation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, nuxtjs, typescript
- Domain
- build-system, full-stack
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100