Skip to content

Commit 3906e4f

Browse files
authored
docs: evaluate Browser bootstrap per request and fix the Node offline default (#853)
Follow-up to #852. These two review fixes were ready after #852 entered the merge queue, so they missed it. - **Browser README bootstrap example:** it called `getFlagsForBootstrap()` once at server startup and served that snapshot on every request. Bootstrapped clients skip their initial fetch, so flag changes didn't reach pages until the server restarted. The example now evaluates flags inside the request handler and keeps the shared Node client. - **Node README `offline` option:** it said offline mode defaults to `true` based on a `TEST` environment variable. The SDK actually checks `NODE_ENV === "test"` (`client.ts`), so the description now says that. - **Browser README script tag:** it loaded `cdn.jsdelivr.net/npm/@reflag/browser-sdk@2`, a major-pinned URL carried over from v1. The docs check keeps major-pinned installs out of the SDK pages and in the upgrade guide, so the example now loads `@reflag/browser-sdk` without a version. --------- Co-authored-by: Ron Cohen <744+roncohen@users.noreply.github.com>
1 parent 1231e44 commit 3906e4f

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

‎packages/browser-sdk/README.md‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,14 @@ import { ReflagClient as ReflagNodeClient } from "@reflag/node-sdk";
290290
const serverClient = new ReflagNodeClient({ secretKey: "your-secret-key" });
291291
await serverClient.initialize();
292292

293-
const bootstrappedState = serverClient.getFlagsForBootstrap({
294-
user: { id: "user123", name: "John Doe", email: "john@acme.com" },
295-
company: { id: "company456", name: "Acme Inc", plan: "enterprise" },
296-
});
297-
298293
// Pass the bootstrapped state to the client using your framework's preferred method.
294+
// Evaluate flags for each request, so pages get the current flags for the current user.
299295
// Escape `<` so flag values or attributes can't close the script tag.
300296
app.get("/", (req, res) => {
297+
const bootstrappedState = serverClient.getFlagsForBootstrap({
298+
user: { id: "user123", name: "John Doe", email: "john@acme.com" },
299+
company: { id: "company456", name: "Acme Inc", plan: "enterprise" },
300+
});
301301
const serialized = JSON.stringify(bootstrappedState).replace(/</g, "\\u003c");
302302
res.set("Content-Type", "text/html");
303303
res.send(

‎packages/node-sdk/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ current working directory.
603603
| ----------------------- | ------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------- |
604604
| `secretKey` | string | The secret key used for authentication with Reflag's servers. | REFLAG_SECRET_KEY |
605605
| `logLevel` | string | The log level for the SDK (e.g., `"DEBUG"`, `"INFO"`, `"WARN"`, `"ERROR"`). Default: `INFO` | REFLAG_LOG_LEVEL |
606-
| `offline` | boolean | Operate in offline mode. Default: `false`, except in tests it will default to `true` based off of the `TEST` env. var. In offline mode the SDK does not fetch from Reflag and does not use `flagsFallbackProvider`. | REFLAG_OFFLINE |
606+
| `offline` | boolean | Operate in offline mode. Default: `false`, except when `NODE_ENV` is `test`, where it defaults to `true`. In offline mode the SDK does not fetch from Reflag and does not use `flagsFallbackProvider`. | REFLAG_OFFLINE |
607607
| `apiBaseUrl` | string | The base API URL for the Reflag servers. | REFLAG_API_BASE_URL |
608608
| `flagOverrides` | Record<string, JSON value> | An object specifying flag values to override for testing or local development. See [examples/express/app.test.ts](https://github.com/reflagcom/javascript/tree/main/packages/node-sdk/examples/express/app.test.ts) for how to use `flagOverrides` in tests. | REFLAG_FLAGS_ENABLED, REFLAG_FLAGS_DISABLED |
609609
| `flagsFallbackProvider` | `FlagsFallbackProvider` | Optional provider used to load and save raw flag definitions for fallback startup when the initial live fetch fails. Available only through the constructor. Ignored in offline mode. | - |

0 commit comments

Comments
 (0)