Skip to content

Commit be85106

Browse files
yuinteiyusukebe
andauthored
fix(ssg): pass SSG_CONTEXT to forGetInfoURLRequest (#4810)
* fix(ssg): pass SSG_CONTEXT to forGetInfoURLRequest * add test --------- Co-authored-by: Yusuke Wada <yusuke@kamawada.com>
1 parent d1722e3 commit be85106

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎src/helper/ssg/ssg.test.tsx‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,30 @@ describe('disableSSG/onlySSG middlewares', () => {
647647
})
648648
})
649649

650+
describe('isSSGContext with disableSSG', () => {
651+
it('Should work correctly when used together', async () => {
652+
const app = new Hono()
653+
654+
app.use('*', async (c, next) => {
655+
if (!isSSGContext(c)) {
656+
return next()
657+
}
658+
await next()
659+
})
660+
app.get('/guarded', disableSSG(), (c) => c.html('<h1>should be skipped</h1>'))
661+
app.get('/page', (c) => c.html('<h1>hello</h1>'))
662+
663+
const fsMock: FileSystemModule = {
664+
writeFile: vi.fn(() => Promise.resolve()),
665+
mkdir: vi.fn(() => Promise.resolve()),
666+
}
667+
668+
await expect(toSSG(app, fsMock, { dir: './static' })).resolves.toBeDefined()
669+
expect(fsMock.writeFile).toHaveBeenCalledWith('static/page.html', expect.any(String))
670+
expect(fsMock.writeFile).not.toHaveBeenCalledWith('static/guarded.html', expect.any(String))
671+
})
672+
})
673+
650674
describe('Request hooks - filterPathsBeforeRequestHook and denyPathsBeforeRequestHook', () => {
651675
let app: Hono
652676
let fsMock: FileSystemModule

‎src/helper/ssg/ssg.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export const fetchRoutesContent = function* <
229229
forGetInfoURLRequest = maybeRequest as unknown as AddedSSGDataRequest
230230
}
231231

232-
await pool.run(() => app.fetch(forGetInfoURLRequest))
232+
await pool.run(() => app.fetch(forGetInfoURLRequest, { [SSG_CONTEXT]: true }))
233233

234234
if (!forGetInfoURLRequest.ssgParams) {
235235
if (isDynamicRoute(route.path)) {

0 commit comments

Comments
 (0)