Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/vite-plugin-react-router/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,23 @@ export function netlifyPlugin(options: NetlifyPluginOptions = {}): Plugin {
// Netlify function handler via a virtual module)
config.build ??= {}
config.build.rollupOptions ??= {}
// Preserve any existing rollup input entries (e.g., from react-router's prerender)
// and merge them with our Netlify function handler entry
const existingInput = config.build.rollupOptions.input
let mergedInput: Record<string, string> = {}

if (typeof existingInput === 'string') {
mergedInput['default'] = existingInput
} else if (Array.isArray(existingInput)) {
existingInput.forEach((entry, i) => {
mergedInput[`entry-${i}`] = entry
})
} else if (existingInput && typeof existingInput === 'object') {
mergedInput = { ...existingInput }
}

config.build.rollupOptions.input = {
...mergedInput,
[FUNCTION_HANDLER_CHUNK]: FUNCTION_HANDLER_MODULE_ID,
}
config.build.rollupOptions.output ??= {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export default {
// Config options...
// Server-side render by default, to enable SPA mode set this to `false`
ssr: true,
// TODO(serhalp) Revisit this if RR team changes their minds:
// https://github.com/remix-run/react-router/issues/13226#issuecomment-2776672461.
// prerender: ['/prerendered'],
// Previously disabled due to https://github.com/remix-run/react-router/issues/13226#issuecomment-2776672461.
// Now enabled after fixing rollupOptions.input merge in plugin.ts to preserve existing entries
// including 'virtual:react-router/server-build'.
prerender: ['/prerendered'],
} satisfies Config
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export default {
// Config options...
// Server-side render by default, to enable SPA mode set this to `false`
ssr: true,
// TODO(serhalp) Revisit this if RR team changes their minds:
// https://github.com/remix-run/react-router/issues/13226#issuecomment-2776672461.
// prerender: ['/prerendered'],
// Previously disabled due to https://github.com/remix-run/react-router/issues/13226#issuecomment-2776672461.
// Now enabled after fixing rollupOptions.input merge in plugin.ts to preserve existing entries
// including 'virtual:react-router/server-build'.
prerender: ['/prerendered'],
} satisfies Config
12 changes: 6 additions & 6 deletions tests/e2e/react-router-user-journeys.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ test.describe('React Router user journeys', () => {
expect(response?.headers()['cache-status']).toMatch(CACHE_STATUS_SERVED_FROM_EDGE)
})

// TODO(serhalp) Revisit this if RR team changes their minds:
// https://github.com/remix-run/react-router/issues/13226#issuecomment-2776672461.
test.skip('serves a response from the CDN (without compute) for a pre-rendered route', async ({
// Previously skipped due to https://github.com/remix-run/react-router/issues/13226#issuecomment-2776672461.
// Now enabled after fixing rollupOptions.input merge in plugin.ts to preserve existing entries.
test('serves a response from the CDN (without compute) for a pre-rendered route', async ({
page,
reactRouterServerlessSite,
}) => {
Expand Down Expand Up @@ -177,9 +177,9 @@ test.describe('React Router user journeys', () => {
expect(response?.headers()['cache-status']).toMatch(CACHE_STATUS_SERVED_FROM_EDGE)
})

// TODO(serhalp) Revisit this if RR team changes their minds:
// https://github.com/remix-run/react-router/issues/13226#issuecomment-2776672461.
test.skip('serves a response from the CDN (without compute) for a pre-rendered route', async ({
// Previously skipped due to https://github.com/remix-run/react-router/issues/13226#issuecomment-2776672461.
// Now enabled after fixing rollupOptions.input merge in plugin.ts to preserve existing entries.
test('serves a response from the CDN (without compute) for a pre-rendered route', async ({
page,
reactRouterEdgeSite,
}) => {
Expand Down