diff --git a/.claude/CLAUDE-KNOWLEDGE.md b/.claude/CLAUDE-KNOWLEDGE.md index a219be226..ebd0e38ac 100644 --- a/.claude/CLAUDE-KNOWLEDGE.md +++ b/.claude/CLAUDE-KNOWLEDGE.md @@ -571,3 +571,6 @@ A: Use `jiti` to import the user's config module, matching `stack config push`, ## Q: What is needed to put the legacy Fumadocs `docs/` app back into the Hexclave pnpm workspace? A: Add `docs` to `pnpm-workspace.yaml`, keep the package named `@hexclave/docs`, use `workspace:*` for `@hexclave/next` and `@hexclave/shared`, and update actual app imports from `@stackframe/stack`/`@stackframe/stack-shared` to `@hexclave/next`/`@hexclave/shared`. Docs app runtime env reads should prefer `NEXT_PUBLIC_HEXCLAVE_*`/`HEXCLAVE_*` while retaining legacy `STACK_*` fallbacks. + +## Q: How should template React contexts avoid duplicate client-bundle context identities? +A: Define exported provider contexts such as `StackContext` and `TranslationContext` through `createGlobal` from `@stackframe/stack-shared/dist/utils/globals`, not direct `React.createContext(...)` exports. That helper stores the React context under `globalThis[Symbol.for("__hexclave-globals")]`, so duplicated SDK bundles still share the same provider/consumer context object. diff --git a/.github/assets/hexclave-header.svg b/.github/assets/hexclave-header.svg index 36ad27ac5..c921de019 100644 --- a/.github/assets/hexclave-header.svg +++ b/.github/assets/hexclave-header.svg @@ -1 +1 @@ -Hexclave +Hexclave diff --git a/packages/template/src/providers/stack-context.tsx b/packages/template/src/providers/stack-context.tsx index 7f9cca302..289da0fd2 100644 --- a/packages/template/src/providers/stack-context.tsx +++ b/packages/template/src/providers/stack-context.tsx @@ -1,8 +1,15 @@ "use client"; import React from "react"; +import { createGlobal } from "@stackframe/stack-shared/dist/utils/globals"; import type { StackClientApp } from "../lib/stack-app/apps/interfaces/client-app"; -export const StackContext = React.createContext, -}>(null); +}; + +export const StackContext = createGlobal>( + "StackContext", + () => React.createContext(null), +); +StackContext.displayName ??= "StackContext"; diff --git a/packages/template/src/providers/translation-provider-client.tsx b/packages/template/src/providers/translation-provider-client.tsx index 6c3407c45..693b6f570 100644 --- a/packages/template/src/providers/translation-provider-client.tsx +++ b/packages/template/src/providers/translation-provider-client.tsx @@ -1,11 +1,18 @@ "use client"; -import { createContext, useContext } from "react"; +import React from "react"; +import { createGlobal } from "@stackframe/stack-shared/dist/utils/globals"; -export const TranslationContext = createContext, quetzalLocale: Map, -}>(null); +}; + +export const TranslationContext = createGlobal>( + "TranslationContext", + () => React.createContext(null), +); +TranslationContext.displayName ??= "TranslationContext"; export function TranslationProviderClient(props: { children: React.ReactNode,