diff --git a/CHANGELOG.md b/CHANGELOG.md index ddf0a6b098..83ec89a610 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -423,6 +423,7 @@ Breaking changes in this release: - Fixed Fluent/Copilot typing indicator animation background color, in PR [#5770](https://github.com/microsoft/BotFramework-WebChat/pull/5770), by [@OEvgeny](https://github.com/OEvgeny) - Fixed `` should not re-render when `attachment[ForScreenReader]Middleware` is updated without noticeable different (`iterateEquals`), by [@compulim](https://github.com/compulim), in PR [#5779](https://github.com/microsoft/BotFramework-WebChat/pull/5779) - Fixed send box should narrate `aria-label` prop, by [@compulim](https://github.com/compulim), in PR [#5805](https://github.com/microsoft/BotFramework-WebChat/pull/5805) +- Fixed polymiddleware error should not propagate to React runtime if `` is not mounted, by [@compulim](https://github.com/compulim), in PR [#5833](https://github.com/microsoft/BotFramework-WebChat/pull/5833) ## [4.18.0] - 2024-07-10 diff --git a/__tests__/html2/adaptiveCard/renderError.withoutDebug.html b/__tests__/html2/adaptiveCard/renderError.withoutDebug.html new file mode 100644 index 0000000000..ff60cb9aec --- /dev/null +++ b/__tests__/html2/adaptiveCard/renderError.withoutDebug.html @@ -0,0 +1,96 @@ + + + + + + + + + + + + + +
+ + + diff --git a/__tests__/html2/adaptiveCard/renderError.withoutDebug.html.snap-1.png b/__tests__/html2/adaptiveCard/renderError.withoutDebug.html.snap-1.png new file mode 100644 index 0000000000..e51ea14624 Binary files /dev/null and b/__tests__/html2/adaptiveCard/renderError.withoutDebug.html.snap-1.png differ diff --git a/__tests__/html2/middleware/errorBox/proxy.html b/__tests__/html2/middleware/errorBox/proxy.html new file mode 100644 index 0000000000..05e2750a04 --- /dev/null +++ b/__tests__/html2/middleware/errorBox/proxy.html @@ -0,0 +1,109 @@ + + + + + + + + + + + + + + +
+ + + diff --git a/__tests__/html2/middleware/errorBox/simple.html.snap-1.png b/__tests__/html2/middleware/errorBox/proxy.html.snap-1.png similarity index 100% rename from __tests__/html2/middleware/errorBox/simple.html.snap-1.png rename to __tests__/html2/middleware/errorBox/proxy.html.snap-1.png diff --git a/__tests__/html2/middleware/errorBox/simple.noDebugProvider.html b/__tests__/html2/middleware/errorBox/proxy.noDebugProvider.html similarity index 67% rename from __tests__/html2/middleware/errorBox/simple.noDebugProvider.html rename to __tests__/html2/middleware/errorBox/proxy.noDebugProvider.html index c3ed21e30a..3b196c5edb 100644 --- a/__tests__/html2/middleware/errorBox/simple.noDebugProvider.html +++ b/__tests__/html2/middleware/errorBox/proxy.noDebugProvider.html @@ -2,7 +2,7 @@ diff --git a/__tests__/html2/middleware/errorBox/proxy.noDebugProvider.html.snap-1.png b/__tests__/html2/middleware/errorBox/proxy.noDebugProvider.html.snap-1.png new file mode 100644 index 0000000000..fd86bed166 Binary files /dev/null and b/__tests__/html2/middleware/errorBox/proxy.noDebugProvider.html.snap-1.png differ diff --git a/__tests__/html2/middleware/errorBox/simple.html b/__tests__/html2/middleware/errorBox/useBuildRenderCallback.html similarity index 78% rename from __tests__/html2/middleware/errorBox/simple.html rename to __tests__/html2/middleware/errorBox/useBuildRenderCallback.html index 6b5a64aec6..265c07b330 100644 --- a/__tests__/html2/middleware/errorBox/simple.html +++ b/__tests__/html2/middleware/errorBox/useBuildRenderCallback.html @@ -2,6 +2,21 @@ + diff --git a/__tests__/html2/middleware/errorBox/useBuildRenderCallback.html.snap-1.png b/__tests__/html2/middleware/errorBox/useBuildRenderCallback.html.snap-1.png new file mode 100644 index 0000000000..ecb1cce43e Binary files /dev/null and b/__tests__/html2/middleware/errorBox/useBuildRenderCallback.html.snap-1.png differ diff --git a/__tests__/html2/middleware/errorBox/useBuildRenderCallback.noDebugProvider.html b/__tests__/html2/middleware/errorBox/useBuildRenderCallback.noDebugProvider.html new file mode 100644 index 0000000000..54decfeed9 --- /dev/null +++ b/__tests__/html2/middleware/errorBox/useBuildRenderCallback.noDebugProvider.html @@ -0,0 +1,9 @@ + + + + + + + diff --git a/__tests__/html2/middleware/errorBox/simple.noDebugProvider.html.snap-1.png b/__tests__/html2/middleware/errorBox/useBuildRenderCallback.noDebugProvider.html.snap-1.png similarity index 100% rename from __tests__/html2/middleware/errorBox/simple.noDebugProvider.html.snap-1.png rename to __tests__/html2/middleware/errorBox/useBuildRenderCallback.noDebugProvider.html.snap-1.png diff --git a/__tests__/html2/part-grouping/index.html b/__tests__/html2/part-grouping/index.html index 151b8b3d8b..2421ef19d9 100644 --- a/__tests__/html2/part-grouping/index.html +++ b/__tests__/html2/part-grouping/index.html @@ -417,6 +417,7 @@ // Then: show the closing message after the list await pageConditions.numActivitiesShown(6); + await pageConditions.scrollToBottomCompleted(); await host.snapshot('local'); }); diff --git a/packages/api-middleware/src/errorBoxPolymiddleware.tsx b/packages/api-middleware/src/errorBoxPolymiddleware.tsx index 92575e0352..0932979884 100644 --- a/packages/api-middleware/src/errorBoxPolymiddleware.tsx +++ b/packages/api-middleware/src/errorBoxPolymiddleware.tsx @@ -1,5 +1,5 @@ import { validateProps } from '@msinternal/botframework-webchat-react-valibot'; -import React, { memo, useMemo } from 'react'; +import React, { memo, useCallback, useMemo } from 'react'; import { object, pipe, readonly, string, unknown, type InferInput } from 'valibot'; import templatePolymiddleware, { @@ -18,7 +18,7 @@ const { Provider: ErrorBoxPolymiddlewareProvider, Proxy, reactComponent: errorBoxComponent, - useBuildRenderCallback: useBuildRenderErrorBoxCallback + useBuildRenderCallback } = templatePolymiddleware<{ readonly error: unknown; readonly where: string }, { readonly children?: never }>( 'ErrorBox' ); @@ -41,15 +41,27 @@ const ErrorBoxPolymiddlewareProxyPropsSchema = pipe( type ErrorBoxPolymiddlewareProxyProps = Readonly>; +// If no error box is defined, do not fallthrough into RCoR and it would error out. Render nothing instead. +const NullComponent = () => null; + // A friendlier version than the organic . const ErrorBoxPolymiddlewareProxy = memo(function ErrorBoxPolymiddlewareProxy(props: ErrorBoxPolymiddlewareProxyProps) { const { error, where } = validateProps(ErrorBoxPolymiddlewareProxyPropsSchema, props); const request = useMemo(() => ({ error, where }), [error, where]); - return ; + return ; }); +const useBuildRenderErrorBoxCallback: typeof useBuildRenderCallback = () => { + const buildRenderCallback = useBuildRenderCallback(); + + return useCallback( + (request, options) => buildRenderCallback(request, Object.freeze({ fallbackComponent: NullComponent, ...options })), + [buildRenderCallback] + ); +}; + export { createErrorBoxPolymiddleware, errorBoxComponent,