Skip to content

OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.

Python

fix unstable context provider (#2026)

Mike Fortman71756465181e
diff --git a/frontend/contexts/brand-context.tsx b/frontend/contexts/brand-context.tsx
index 8744c876a..943a919ad 100644
--- a/frontend/contexts/brand-context.tsx
+++ b/frontend/contexts/brand-context.tsx
@@ -1,6 +1,13 @@
"use client";
-import { createContext, useContext, useEffect, useState } from "react";
+import {
+ createContext,
+ useCallback,
+ useContext,
+ useEffect,
+ useMemo,
+ useState,
+} from "react";
import { useAuth } from "@/contexts/auth-context";
import {
type Brand,
@@ -48,16 +55,19 @@ export function BrandProvider({ children }: { children: React.ReactNode }) {
applyBrand(brand);
}, [brand]);
- function setBrand(newBrand: Brand) {
- if (isIbmAuthMode) return;
- localStorage.setItem("brand", newBrand);
- setStoredBrandState(newBrand);
- }
+ const setBrand = useCallback(
+ (newBrand: Brand) => {
+ if (isIbmAuthMode) return;
+ localStorage.setItem("brand", newBrand);
+ setStoredBrandState(newBrand);
+ },
+ [isIbmAuthMode],
+ );
+
+ const value = useMemo(() => ({ brand, setBrand }), [brand, setBrand]);
return (
- <BrandContext.Provider value={{ brand, setBrand }}>
- {children}
- </BrandContext.Provider>
+ <BrandContext.Provider value={value}>{children}</BrandContext.Provider>
);
}