From 0cf4a3fa65e02d9719d8f2e8a66d4e0a958eb230 Mon Sep 17 00:00:00 2001 From: Julien Ripouteau Date: Sun, 24 Mar 2024 17:51:54 +0100 Subject: [PATCH] fix: enable ssr everywhere if `pages` is not defined --- src/inertia.ts | 4 +++- tests/inertia.spec.ts | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/inertia.ts b/src/inertia.ts index 59ab8cc..ca647fd 100644 --- a/src/inertia.ts +++ b/src/inertia.ts @@ -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 diff --git a/tests/inertia.spec.ts b/tests/inertia.spec.ts index 4e3bf25..60d59b9 100644 --- a/tests/inertia.spec.ts +++ b/tests/inertia.spec.ts @@ -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' } } })