Interweave SSR (Server-Side Rendering) is a utility package designed to enable the Interweave React component library to function correctly in Node.js environments. It addresses the common issue in SSR setups where browser-specific global objects like `document` and `window` are absent, causing runtime errors for libraries that expect them. This package, currently at version 2.0.0, provides a simple `polyfill()` function that simulates the necessary DOM APIs within the Node.js context, allowing `Interweave` components to render without errors during the server-side generation phase. Its release cadence is closely tied to the main `Interweave` library, ensuring compatibility. It differentiates itself by offering a targeted polyfill solution specifically for `Interweave`, rather than a broad, potentially over-engineered, general-purpose DOM emulation library. It is crucial for applications using `Interweave` that require universal rendering capabilities.
npm install interweave-ssrVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `interweave-ssr` to enable server-side rendering of an `Interweave` component within a basic React application. It shows the essential `polyfill()` call before rendering.
Ensure `import { polyfill } from 'interweave-ssr'; polyfill();` is placed at the top of your SSR bundle's entry point.Upgrade Node.js to a supported version (>=12.17.0). If using CommonJS, consider transitioning to ESM or using a bundler like Webpack/Rollup with Babel to transpile `interweave-ssr`.
Verify that the `Interweave` component receives identical props and renders the same structure on both the server and client. Use development tools to inspect hydration warnings.
Add `import { polyfill } from 'interweave-ssr'; polyfill();` at the very beginning of your server-side rendering entry file.Ensure your project is configured for ES modules (e.g., `"type": "module"` in `package.json`) or use a bundler (like Webpack with Babel) to transpile your server-side code. For `interweave-ssr` specifically, using `import` requires a module environment.