Skip to content

Commit 1301c37

Browse files
authored
fix(cloudflare): prebundle JSON logger when enabled (#17850)
1 parent 157c500 commit 1301c37

3 files changed

Lines changed: 29 additions & 1 deletion

File tree

.changeset/nine-streets-retire.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@astrojs/cloudflare': patch
3+
---
4+
5+
Fixes React SSR failures on the first Cloudflare dev request when JSON logging is enabled

packages/integrations/cloudflare/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,9 @@ export default function createIntegration({
359359
...(prebundleContentRuntime ? (['astro/content/runtime'] as const) : []),
360360
'astro/compiler-runtime',
361361
'astro/jsx-runtime',
362+
...(config.logger?.entrypoint === 'astro/logger/json'
363+
? ['astro/logger/json']
364+
: []),
362365
'astro/app/entrypoint/dev',
363366
'astro/middleware',
364367
'astro/virtual-modules/middleware.js',

packages/integrations/cloudflare/test/typegen-phase.test.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ interface OptimizeDepsPatch {
1717
optimizeDeps?: { noDiscovery?: boolean; include?: string[]; exclude?: string[] };
1818
}
1919

20-
async function runConfigSetup(command: 'dev' | 'build' | 'sync') {
20+
async function runConfigSetup(
21+
command: 'dev' | 'build' | 'sync',
22+
loggerConfig?: { entrypoint: string },
23+
) {
2124
const integration = cloudflare();
2225
let updatedConfig: { vite: { plugins: unknown[] } } | undefined;
2326

@@ -31,6 +34,7 @@ async function runConfigSetup(command: 'dev' | 'build' | 'sync') {
3134
experimental: {},
3235
vite: {},
3336
image: {},
37+
logger: loggerConfig,
3438
},
3539
updateConfig(config: { vite: { plugins: unknown[] } }) {
3640
updatedConfig = config;
@@ -116,5 +120,21 @@ describe('type generation phase (build and sync)', () => {
116120
assert.ok(include.includes('astro/actions/runtime/entrypoints/server.js'));
117121
assert.ok(include.includes('astro/actions/runtime/entrypoints/route.js'));
118122
});
123+
124+
it('only prebundles the JSON logger when it is enabled', async () => {
125+
const defaultConfig = await runConfigSetup('dev');
126+
const defaultInclude =
127+
defaultConfig.configEnvironment('ssr', {})?.optimizeDeps?.include ?? [];
128+
assert.ok(!defaultInclude.includes('astro/logger/json'));
129+
130+
const consoleConfig = await runConfigSetup('dev', { entrypoint: 'astro/logger/console' });
131+
const consoleInclude =
132+
consoleConfig.configEnvironment('ssr', {})?.optimizeDeps?.include ?? [];
133+
assert.ok(!consoleInclude.includes('astro/logger/json'));
134+
135+
const jsonConfig = await runConfigSetup('dev', { entrypoint: 'astro/logger/json' });
136+
const jsonInclude = jsonConfig.configEnvironment('ssr', {})?.optimizeDeps?.include ?? [];
137+
assert.ok(jsonInclude.includes('astro/logger/json'));
138+
});
119139
});
120140
});

0 commit comments

Comments
 (0)