/** * Janus Gate for React and Next.js. Copy this file into your project as is: * https://www.janus-gate-ai.com/react/janus-gate.tsx * * Why it is needed: your server always renders the baseline. The Janus Gate * script then shows each visitor their assigned version, before React starts, * so nobody sees the text change. When React starts it finds text that * differs from the server's and, unless told this is on purpose, rebuilds * the page with the baseline: visitors are counted for one version while * seeing another. Everything here renders the baseline on the server and * tells React to keep what the script painted. * * 1. Root layout: * * * * * * * 2. Each block to test (plain text only, no nested elements): * * * * or, on an element you render yourself: * *

{mabBaseline(test).text}

* * 3. The action that counts: data-mab-convert="click" as usual. Forms and * buttons need nothing else. * * No "use client": works in Server and Client Components. Blocks that * remount, and pages reached by client-side navigation, keep their version. */ import { createElement, type ComponentPropsWithoutRef, type ElementType, } from "react"; export const JANUS_GATE_ORIGIN = "https://www.janus-gate-ai.com"; /** * Spread on in the root layout. The script marks once each * visitor's versions are on the page (data-mab-ready), before React starts. */ export const janusHtmlProps = { suppressHydrationWarning: true } as const; /** * The Janus Gate script. Put it first in of the root layout. It runs * before the page paints, so it is a plain script: no async, no defer, not * next/script (its later strategies would let the baseline show first). */ export function JanusGateScript({ siteId, origin = JANUS_GATE_ORIGIN, languages = "separate", lang, }: { /** The project's tracking id, from the Janus Gate dashboard. */ siteId: string; origin?: string; /** "shared": every language of the page shares one test. */ languages?: "separate" | "shared"; /** Only when has no lang attribute: the page's language, e.g. "es". */ lang?: string; }) { return createElement("script", { src: `${origin}/mab.js`, "data-site-id": siteId, "data-api-base": origin, "data-mab-lang": languages === "shared" ? "off" : lang, // React warns in development when it renders a