A production-ready integration is available in this repository: https://github.com/Kameleoon/setup-engine-nextjs Be sure to replace the sitecode with your own inDocumentation Index
Fetch the complete documentation index at: https://docs.kameleoon.com/llms.txt
Use this file to discover all available pages before exploring further.
src/integrations/Kameleoon/sitecode.ts.
Your Kameleoon script domain may differ between projects. Depending on their creation date, your projects may be hosted under
kameleoon.eu or kameleoon.io. Always use the domain displayed for your project inside the Kameleoon App.Overview
- Preload the Kameleoon engine so the browser downloads it early and caches it.
- Apply anti-flicker CSS to hide content until the engine is ready, preventing layout shifts.
- Run the engine after hydration to avoid React hydration warnings or mismatches.
Components
This integration uses two components that work together to ensure smooth loading and prevent flickering during hydration.1. Server Component
Place this component inside the <head> of your main layout.
Its responsibilities are:
- Injecting anti-flicker CSS during SSR to prevent UI flashing
- Preloading the
engine.jsfile so downloading starts as soon as possible
KameleoonHead.tsx
2. Client Component
Place this component at the very top of the <body> to accurately control execution timing.
This component:
- Removes the anti-flicker styles after hydration
- Dynamically loads Kameleoon’s
engine.js - Ensures the script loads without blocking rendering
KameleoonHydrationReady.tsx
Note: The default anti-flicker timeout is500 ms. AdjustkameleoonLoadingTimeoutif needed.
Usage in RootLayout
Example of how to combine both components:
layout.tsx
Key Takeaways
- Anti-flicker protection on SSR
- Hydration-aware script execution
- Asynchronous engine loading
- Fallback timeout for reliability
- No blocking scripts
- Works with Next.js layouts, streaming, and React Server Components