Supporting routes with layout and different props was broken
Prerequisites
- [X] I have written a descriptive issue title
- [X] I have searched existing issues to ensure the regression has not already been reported
Last working version
2.2.0-beta.2
Stopped working in version
2.2.3
Node.js version
14.18.1
Operating system
Windows
Operating system version (i.e. 20.04, 11.3, 10)
Windows 10
💥 Regression Report
Hi There.
My test example is placed here (https://github.com/SuslegStyle/fastify-vite-hello-world) Let me describe my use case.
I have a custom routes.js file where I define routes like
export default () => [
{
path: '/',
component: Layout,
props: {testProperty: 'Hello world'},
children: [
{
path: '',
component: Index,
}
]
},
{
path: '/',
component: Layout,
props: {testProperty: 'Hello external world'},
children: [
{
path: 'external/',
component: Index //TODO: in real app it is another page component
}
]
}
];
I use props to pass correct value to layout. In the real app, the props value changes Header.
After upgrading to 2.2.3 I start getting error during the build
Method 'GET' already declared for route '/' with constraints '{}'
Steps to Reproduce
First issue
- Clone my example
- Run
npm run build
internal/process/promises.js:213
triggerUncaughtException(err, true /* fromPromise */);
^
AssertionError [ERR_ASSERTION]: Method 'GET' already declared for route '/' with constraints '{}'
at Router._insert (D:\fastify-vite-hello-world\node_modules\find-my-way\index.js:303:7)
at Router._on (D:\fastify-vite-hello-world\node_modules\find-my-way\index.js:231:8)
at Router.on (D:\fastify-vite-hello-world\node_modules\find-my-way\index.js:100:8)
at Object.afterRouteAdded (D:\fastify-vite-hello-world\node_modules\fastify\lib\route.js:254:16)
at D:\fastify-vite-hello-world\node_modules\fastify\lib\route.js:181:25
at Object._encapsulateThreeParam (D:\fastify-vite-hello-world\node_modules\avvio\boot.js:551:7)
at Boot.timeoutCall (D:\fastify-vite-hello-world\node_modules\avvio\boot.js:447:5)
at Boot.callWithCbOrNextTick (D:\fastify-vite-hello-world\node_modules\avvio\boot.js:428:19)
at Boot._after (D:\fastify-vite-hello-world\node_modules\avvio\boot.js:273:26)
at Plugin.exec (D:\fastify-vite-hello-world\node_modules\avvio\plugin.js:132:19) {
generatedMessage: false,
code: 'ERR_ASSERTION',
actual: false,
expected: true,
operator: '=='
}
Second issue
There is a second issue, that start reproducing again.
If in my routes.js change line 18 to path: '/my', then we get the error
D:\fastify-vite-hello-world\node_modules\fastify-vite\build.js:25
const outDir = vite.build.outDir || 'dist'
^
TypeError: Cannot read property 'build' of null
at build (D:\fastify-vite-hello-world\node_modules\fastify-vite\build.js:25:23)
at Object.fastify.vite.ready (D:\fastify-vite-hello-world\node_modules\fastify-vite\index.js:208:13)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async main (D:\fastify-vite-hello-world\server.js:30:5)
Third issue
I tried to change fastify-vite/build.js file at line 25
from const outDir = vite.build.outDir || 'dist'
to const outDir = vite?.build?.outDir || 'dist'
Then the application is built successfully, but I got the runtime error that appContext is null. (We already faced the issue before)
TypeError: Cannot read property 'appContext' of null
at useGlobalProperties (/node_modules/fastify-vite-vue/client.mjs?v=e94165ef:133:30)
at Module.useHydration (/node_modules/fastify-vite-vue/client.mjs?v=e94165ef:20:23)
at setup (d:/fastify-vite-hello-world/pages/index.vue:8:24)
at _sfc_main.setup (/pages/index.vue:48:23)
at callWithErrorHandling (D:\fastify-vite-hello-world\node_modules\vue\node_modules\@vue\runtime-core\dist\runtime-core.cjs.js:6620:22)
at setupStatefulComponent (D:\fastify-vite-hello-world\node_modules\vue\node_modules\@vue\runtime-core\dist\runtime-core.cjs.js:6246:29)
at setupComponent (D:\fastify-vite-hello-world\node_modules\vue\node_modules\@vue\runtime-core\dist\runtime-core.cjs.js:6202:11)
at renderComponentVNode (D:\fastify-vite-hello-world\node_modules\vue\node_modules\@vue\server-renderer\dist\server-renderer.cjs.js:198:17)
at renderVNode (D:\fastify-vite-hello-world\node_modules\vue\node_modules\@vue\server-renderer\dist\server-renderer.cjs.js:304:22)
at renderVNode (D:\fastify-vite-hello-world\node_modules\vue\node_modules\@vue\server-renderer\dist\server-renderer.cjs.js:310:17)
Expected Behavior
The application should be successfully built and works properly.