Skip to content

Commit

Permalink
fix: disallow nested ThreadConfigs (#1200)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonom authored Nov 20, 2024
1 parent 10d70db commit c3027a0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/tough-spoons-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@assistant-ui/react": patch
---

fix: disallow nested ThreadConfigs
23 changes: 16 additions & 7 deletions packages/react/src/ui/thread-config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,23 @@ export const ThreadConfigProvider: FC<ThreadConfigProviderProps> = ({
}) => {
const hasAssistant = !!useAssistantRuntime({ optional: true });

const configProvider =
config && Object.keys(config ?? {}).length > 0 ? (
<ThreadConfigContext.Provider value={config}>
{children}
</ThreadConfigContext.Provider>
) : (
<>{children}</>
const hasConfig = config && Object.keys(config).length > 0;
const outerConfig = useThreadConfig();

if (hasConfig && Object.keys(outerConfig).length > 0) {
throw new Error(
"You are providing ThreadConfig to several nested components. Please provide all configuration to the same component.",
);
}

const configProvider = hasConfig ? (
<ThreadConfigContext.Provider value={config}>
{children}
</ThreadConfigContext.Provider>
) : (
<>{children}</>
);

if (!config?.runtime) return configProvider;

if (hasAssistant) {
Expand Down

0 comments on commit c3027a0

Please sign in to comment.