Wait for server initialization

You can manually trigger and wait for server initialization with hypertune.initIfNeeded():

import hypertune from "./hypertune";

export default async function ServerExample() {
  await hypertune.initIfNeeded();

  const rootNode = hypertune.root({
    args: {
      context: {
        user: { id: "test_id", name: "Test", email: "test@test.com" },
      },
    },
  });

  const exampleFlag = rootNode.exampleFlag({ fallback: false });

  return (
    <div>Server Component flag: {String(exampleFlag)}</div>
  );
}

This will only trigger a new server initialization if the last one was over a second ago so you can call this on every backend request to ensure flag values are fresh while minimizing network latency and bandwidth.

This is particularly useful in serverless environments, e.g. Vercel deployments, where background SDK tasks like fetching updates aren't guaranteed to execute.

Check for server initialization

You can also check for server initialization with !!hypertune.getLastDataProviderInitTime():

import hypertune from "./hypertune";
import useHypertune from "./useHypertune";

export default function ClientExample() {
  const rootNode = useHypertune();

  if (!hypertune.getLastDataProviderInitTime()) {
    return null;
  }

  const exampleFlag = rootNode.exampleFlag({ fallback: false });

  return <div>Client Component flag: {String(exampleFlag)}</div>;
}

Last updated