+ Discover the features that make our platform the best choice for your needs. +
+{feature.description}
++ Discover the features that make our platform the best choice for your needs. +
+{feature.description}
++ Discover the features that make our platform the best choice for your needs. +
+{feature.description}
++ Discover the features that make our platform the best choice for your needs. +
+{feature.description}
++ Discover the features that make our platform the best choice for your needs. +
+{feature.description}
++ Discover the features that make our platform the best choice for your needs. +
+{feature.description}
+( +Control: React.ComponentType
, +opts: WithExperimentOpts +): React.ComponentType
void; probat?: { trackClick: () => void } }> { +const { proposalId, registry } = opts; + +function Wrapped(props: P) { + const [choice, setChoice] = React.useState<{ experiment_id: string; label: string } | null>(null); + + React.useEffect(() => { + let alive = true; + + const cached = readChoice(proposalId); + if (cached) { + setChoice({ experiment_id: cached.experiment_id, label: cached.label }); + } + + if (!cached) { + (async () => { + try { + const { experiment_id, label } = await fetchDecision(ENV_BASE, proposalId); + if (!alive) return; + setChoice({ experiment_id, label }); + } catch (e) { + if (!alive) return; + setChoice({ experiment_id: `exp_${proposalId}`, label: "control" }); + } + })(); + } + + return () => { alive = false; }; + }, [proposalId]); + + React.useEffect(() => { + const exp = choice?.experiment_id; + const lbl = choice?.label ?? "control"; + if (!lbl) return; + recordVisit(ENV_BASE, proposalId, exp ?? undefined, lbl); + }, [proposalId, choice?.experiment_id, choice?.label]); + + const trackClick = React.useCallback( + (event?: React.MouseEvent | null, options?: { force?: boolean }) => { + const exp = choice?.experiment_id; + const lbl = choice?.label ?? "control"; + const meta = extractClickMeta(event ?? undefined); + if (!options?.force && event && !meta) { + return false; + } + void sendClickMetric(ENV_BASE, proposalId, exp, lbl, meta); + return true; + }, + [proposalId, choice?.experiment_id, choice?.label] + ); + + const label = choice?.label ?? "control"; + const Variant = registry[label] || Control; + + const key = `${proposalId}:${label}`; + return ( +