import React, { Suspense } from 'react'; import { PageWrapper } from './PageWrapper'; import { escapeInject, dangerouslySkipEscape } from 'vike/server'; import { getDataFromTree } from '@apollo/client/react/ssr'; import { ApolloProvider } from '@apollo/client'; import { getPageMeta } from './getPageMeta'; import { I18nextProvider } from 'react-i18next'; import i18n from './i18n'; import { PageContext } from '../types'; // See https://vike.dev/data-fetching // Note: urlParsed and urlPathname are automatically available in Client Routing, // but we must explicitly pass them for Server Routing compatibility export const passToClient = [ 'pageProps', 'urlParsed', // Required for Server Routing (used in catalog components) 'urlPathname', // Required for Server Routing (used for key props and Link active state) 'apolloInitialState', 'heliumEndpoint', 'appearance', 'documentProps', 'currentUser', 'isProduction', 'queryParams', 'authToken', 'routeParams', 'assetUrls' ]; export { render }; type RenderFn = (pageContext: PageContext) => Promise<{ documentHtml: ReturnType; pageContext: Record; }>; const render: RenderFn = async pageContext => { const { Page, pageProps, apolloClient, appearance, currentUser, queryParams, assetUrls } = pageContext; // See https://vike.dev/html-head const documentProps = getPageMeta(pageContext); const title = (documentProps && documentProps.title) || 'Vite SSR app'; const desc = (documentProps && documentProps.description) || 'App using Vite + vike'; if (currentUser && currentUser.lang) { i18n.changeLanguage(currentUser.lang); } const tree = ( ); const pageHtml = await getDataFromTree(tree); const apolloInitialState = apolloClient.extract(); // Build asset tags if provided (from Worker environment) // IMPORTANT: In Server Routing mode, Vike automatically injects JavaScript during SSR // We should ONLY manually inject CSS files to avoid "client runtime loaded twice" errors // The mapVikeAssets function in static-assets.js handles URL resolution for JavaScript let assetTags = ''; if (assetUrls && assetUrls.styles && assetUrls.styles.length > 0) { // Only inject CSS files - these are safe and don't cause runtime duplication assetTags += assetUrls.styles .map((url: string) => ``) .join('\n'); } // DO NOT manually inject JavaScript files in Server Routing mode // Vike handles JavaScript injection automatically during SSR // The mapVikeAssets function in static-assets.js will resolve the URLs const documentHtml = escapeInject` ${title} ${dangerouslySkipEscape(assetTags)}
${dangerouslySkipEscape(pageHtml)}
`; return { documentHtml, pageContext: { apolloInitialState } }; };