Repository navigation
Description
Problem
When a page loader calls c.notFound() and a static file exists at the same path, the static file is rendered as the page props instead of a 404 page.
Versions: void@1.7.0, @void/vue@1.7.0.
Reproduction
https://gist.github.com/wintercn/c91780104141a616d9f13bbed21b474a
The page loader of /docs/:name returns { doc: { title: 'Intro' } } for intro and calls c.notFound() otherwise. public/docs/readme.json contains { "static": "docs" }. Run npm run build and npm run preview.
Fresh preview process, request in this order:
/docs/intro 200 text/html <h1>Intro</h1>
/docs/readme.json 200 text/html empty page, log: TypeError: Cannot read properties of undefined (reading 'title')
/docs/intro 200 text/html <h1>Intro</h1>
Fresh preview process, request in this order:
/docs/readme.json 200 text/html empty page, log: TypeError: Cannot read properties of undefined (reading 'title')
/docs/intro 200 text/html empty page, log: TypeError: Cannot read properties of undefined (reading 'title')
In the second process, every later /docs/intro stays empty because of #773.
Expected
/docs/readme.json returns the 404 page.
Analysis
createPagesFallbackis registered as the globalapp.notFound(void/dist/index.mjs:2606). Its first step isassets.fetch(c.req.raw)(void/dist/runtime/routing.mjs:221), and it returns the asset when the status is not404.- Hono calls this global handler for
c.notFound()in a page loader, although the route has already matched. runLoader(void/dist/protocol-yxdHxFLN.mjs:170) treats a200application/jsonResponseas page props, so the static file content is rendered as props.
A possible fix: when notFound() is called in a page context, render the 404 page without looking up static assets.
问题
页面 loader 调用 c.notFound() 时,如果同一路径存在静态文件,这个静态文件会被当作页面 props 渲染,而不是返回 404 页面。
版本:void@1.7.0、@void/vue@1.7.0。
复现
https://gist.github.com/wintercn/c91780104141a616d9f13bbed21b474a
/docs/:name 的页面 loader 对 intro 返回 { doc: { title: 'Intro' } },其他情况调用 c.notFound()。public/docs/readme.json 的内容是 { "static": "docs" }。执行 npm run build 和 npm run preview。
新预览进程,依次请求:
/docs/intro 200 text/html <h1>Intro</h1>
/docs/readme.json 200 text/html empty page, log: TypeError: Cannot read properties of undefined (reading 'title')
/docs/intro 200 text/html <h1>Intro</h1>
新预览进程,依次请求:
/docs/readme.json 200 text/html empty page, log: TypeError: Cannot read properties of undefined (reading 'title')
/docs/intro 200 text/html empty page, log: TypeError: Cannot read properties of undefined (reading 'title')
第二个进程中,由于 #773,之后的 /docs/intro 一直是空页面。
预期
/docs/readme.json 返回 404 页面。
分析
createPagesFallback被注册为全局的app.notFound(void/dist/index.mjs:2606),第一步就是assets.fetch(c.req.raw)(void/dist/runtime/routing.mjs:221),状态不是404就直接返回这个文件。- 页面 loader 里的
c.notFound()会调用这个全局处理器,而此时路由已经匹配。 runLoader(void/dist/protocol-yxdHxFLN.mjs:170)把200的application/jsonResponse当作页面 props,静态文件的内容因此被当作 props 渲染。
可行的修法:在页面上下文中调用 notFound() 时,直接输出 404 页面,不查静态资源。
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
0froq commentedon Nov 13, 2026
I can reproduce this on
main. The loader returns the fallback's response, because Hono resolvesc.notFound()inside the call, and a 200 JSON static file at that path is then read as page props. I'll open a PR shortly.fix(pages): keep a static file out of a loader not-found response (vo…