diff --git a/.changeset/afraid-ducks-scream.md b/.changeset/afraid-ducks-scream.md new file mode 100644 index 00000000000..a5fee27c418 --- /dev/null +++ b/.changeset/afraid-ducks-scream.md @@ -0,0 +1,5 @@ +--- +'@itwin/itwinui-react': patch +--- + +Fixed `ThemeProvider` bug of re-mounting its children and losing state when `portalContainer` is toggled between `undefined` and defined. diff --git a/apps/react-workshop/cypress-visual-screenshots/baseline/Table.test.ts-Custom Filter.png b/apps/react-workshop/cypress-visual-screenshots/baseline/Table.test.ts-Custom Filter.png index 643d0002f77..ea4e5c5ca99 100755 Binary files a/apps/react-workshop/cypress-visual-screenshots/baseline/Table.test.ts-Custom Filter.png and b/apps/react-workshop/cypress-visual-screenshots/baseline/Table.test.ts-Custom Filter.png differ diff --git a/apps/react-workshop/cypress-visual-screenshots/baseline/Table.test.ts-Filters.png b/apps/react-workshop/cypress-visual-screenshots/baseline/Table.test.ts-Filters.png index d7eb34f1483..820d28226b0 100755 Binary files a/apps/react-workshop/cypress-visual-screenshots/baseline/Table.test.ts-Filters.png and b/apps/react-workshop/cypress-visual-screenshots/baseline/Table.test.ts-Filters.png differ diff --git a/apps/react-workshop/cypress-visual-screenshots/baseline/Table.test.ts-Localized.png b/apps/react-workshop/cypress-visual-screenshots/baseline/Table.test.ts-Localized.png index 143e04bb539..edfcc8f4041 100755 Binary files a/apps/react-workshop/cypress-visual-screenshots/baseline/Table.test.ts-Localized.png and b/apps/react-workshop/cypress-visual-screenshots/baseline/Table.test.ts-Localized.png differ diff --git a/packages/itwinui-react/src/core/Toast/Toaster.tsx b/packages/itwinui-react/src/core/Toast/Toaster.tsx index 4f3ba151c75..f33f496a1a9 100644 --- a/packages/itwinui-react/src/core/Toast/Toaster.tsx +++ b/packages/itwinui-react/src/core/Toast/Toaster.tsx @@ -104,14 +104,21 @@ export const ToastProvider = ({ }, }); + const toasterDispatchContext = React.useContext(ToasterDispatchContext); + const toasterStateContext = React.useContext(ToasterStateContext); + // Re-use existing ToastProvider if found - if (React.useContext(ToasterStateContext) && inherit) { - return children; - } + const shouldReuse = toasterStateContext && inherit; + const toasterDispatchContextValue = shouldReuse + ? toasterDispatchContext + : dispatch; + const toasterStateContextValue = shouldReuse + ? toasterStateContext + : toasterState; return ( - - + + {children}