Comment on page
Wait for server initialization
You can manually trigger and wait for server initialization with
hypertune.initFromServerIfNeeded()
:import hypertune from "./hypertune";
export default async function ServerExample() {
await hypertune.initFromServerIfNeeded();
const rootNode = hypertune.root({
context: {
user: { id: "test_id", name: "Test", email: "[email protected]" },
},
});
const exampleFlag = rootNode.exampleFlag().get(/* 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.
You can also check for server initialization with
hypertune.hasInitializedFromServer()
:import hypertune from "./hypertune";
import useHypertune from "./useHypertune";
export default function ClientExample() {
const rootNode = useHypertune();
if (!hypertune.hasInitializedFromServer()) {
return null;
}
const exampleFlag = rootNode.exampleFlag().get(/* fallback */ false);
return <div>Client Component flag: {String(exampleFlag)}</div>;
}