SSR and hydration
The server creates the initial HTML, then Svelte connects handlers and client effects. The first markup must match the same data and theme settings in both environments.
Styles on the server
ConfigProvider imports the published CSS of the library. Custom themes and supported local prefixes also form style elements through head Svelte. Do not remove head from the application server template.
In SvelteKit, save %sveltekit.head% in app.html. If ConfigProvider is not used, connect @woodger/antd/styles.css in the general layout. A separate React StyleProvider, extractStyle or @ant-design/cssinjs is not required for Svelte.
Check the production build: the presence of CSS only in the dev server does not confirm the correctness of the SSR. zeroRuntime does not replace the need for published CSS.
Same initial data
Don't calculate the initial value from window, localStorage or DOM sizes during server render. For current time and random values, pass one result from the server, or start a client script after mount.
onMount and $effect are not executed under SSR. Moving the initial value setting only to the effect does not create that value on the server. The initial field, label and error text must have consistent values before hydration.
Place calls to create FormInstance, timers and holders in the component instance. A common mutable model in the server module can share data between requests. Release timers and browser listeners when the component is destroyed.
Theme from cookie
In SvelteKit, the server can select the initial mode from a cookie. Example src/routes/+layout.server.ts:
import type { LayoutServerLoad } from './$types';
export const load: LayoutServerLoad = ({ cookies }) => ({
appearance: cookies.get('appearance') === 'dark' ? 'dark' : 'light'
});
In src/routes/+layout.svelte, convert the string to theme settings:
<script lang="ts">
import type { LayoutProps } from './$types';
import { ConfigProvider, theme } from '@woodger/antd';
let { data, children }: LayoutProps = $props();
</script>
<ConfigProvider theme={{
mode: data.appearance === 'dark' ? 'dark' : 'light',
algorithm: data.appearance === 'dark' ? theme.darkAlgorithm : theme.defaultAlgorithm
}}>
{@render children()}
</ConfigProvider>
Server and client receive the same appearance. The application implements saving the new selection in a cookie and updating the layout data. If the selection is only stored in localStorage, read it after mount and take into account possible visible theme changes.
Dates, popup and adaptability
Dayjs is not a native server load data format. Pass the date as a string or number and restore it on the component side. Maintain the selected locale and explicit time zone; the same ISO string by itself does not guarantee the same text under different formatting settings.
GetPopupContainer must access the DOM inside the callback, and not when initializing the module. The server does not open the browser portal. Start a dialog or popup with a consistent closed state if opening it is browser dependent.
For complex Layout, set hasSider explicitly. Direct child Sider is recognized before hydration; breakpoint and window measurements are connected in the browser. Don't disable SSR for your entire application because of one client dimension.
Checking the result
- Build the application and open the direct URL.
- Check the HTML and design with JavaScript disabled.
- Enable JavaScript: check for hydration, input and keyboard errors.
- Repeat the transition within the application and reboot with the saved theme.
- Check the narrow window, both themes and clearing resources after leaving the page.
Errors in individual scripts are sorted out in FAQ. The structure of the SvelteKit application is described in connecting to SvelteKit.