Skip to content

Commit

Permalink
fix: enable ssr everywhere if pages is not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-R44 committed Mar 24, 2024
1 parent 5355839 commit 0cf4a3f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/inertia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ export class Inertia {
let isSsrEnabledForPage = false
if (typeof this.config.ssr.pages === 'function') {
isSsrEnabledForPage = await this.config.ssr.pages(this.ctx, component)
} else if (this.config.ssr.pages) {
isSsrEnabledForPage = this.config.ssr.pages?.includes(component)
} else {
isSsrEnabledForPage = this.config.ssr.pages?.includes(component) ?? false
isSsrEnabledForPage = true
}

return isSsrEnabledForPage
Expand Down
18 changes: 18 additions & 0 deletions tests/inertia.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,24 @@ test.group('Inertia | Ssr', () => {
assert.deepEqual(result.props.page.ssrHead, ['head'])
})

test('enable everywhere if pages is not defined', async ({ assert, fs }) => {
setupViewMacroMock()
const vite = await setupVite({ build: { rollupOptions: { input: 'foo.ts' } } })

await fs.create('foo.ts', 'export default () => ({ head: "head", body: "foo.ts" })')

const inertia = await new InertiaFactory()
.withVite(vite)
.merge({ config: { ssr: { enabled: true, entrypoint: 'foo.ts' } } })
.create()

const result: any = await inertia.render('foo')
const result2: any = await inertia.render('bar')

assert.deepEqual(result.props.page.ssrBody, 'foo.ts')
assert.deepEqual(result2.props.page.ssrBody, 'foo.ts')
})

test('enable only for listed pages (Array)', async ({ assert, fs }) => {
setupViewMacroMock()
const vite = await setupVite({ build: { rollupOptions: { input: 'foo.ts' } } })
Expand Down

0 comments on commit 0cf4a3f

Please sign in to comment.