@envive-ai/react-widgets-v3 0.3.57 → 0.3.59

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/dist/CXIntegration/hooks/useUnifiedCXButton.cjs +1 -1
  2. package/dist/CXIntegration/hooks/useUnifiedCXButton.js +1 -1
  3. package/dist/debug/GenericSelect.cjs +1 -1
  4. package/dist/debug/GenericSelect.js +1 -1
  5. package/dist/debug/MessageContent.cjs +1 -1
  6. package/dist/debug/MessageContent.js +1 -1
  7. package/dist/debug/chatEmbed.cjs +3 -3
  8. package/dist/debug/chatEmbed.js +2 -2
  9. package/dist/debug/reportIssue.cjs +4 -4
  10. package/dist/debug/reportIssue.js +3 -3
  11. package/dist/hocs/withBaseWidget/types.d.ts +1 -1
  12. package/dist/hocs/withBaseWidget/withBaseWidget.cjs +35 -2
  13. package/dist/hocs/withBaseWidget/withBaseWidget.d.cts +2 -2
  14. package/dist/hocs/withBaseWidget/withBaseWidget.d.ts +2 -2
  15. package/dist/hocs/withBaseWidget/withBaseWidget.js +34 -2
  16. package/dist/packages/widgets/dist/SearchResults/SearchResultsWidget.d.ts +2 -2
  17. package/dist/packages/widgets/dist/SearchZeroState/SearchZeroStateWidget.d.ts +2 -2
  18. package/dist/packages/widgets/dist/SuggestionBar/SuggestionBar.d.ts +2 -2
  19. package/dist/widgets/ChatPreviewComparisonWidget/ChatPreviewComparisonWidget.cjs +3 -3
  20. package/dist/widgets/ChatPreviewComparisonWidget/ChatPreviewComparisonWidget.d.cts +3 -3
  21. package/dist/widgets/ChatPreviewComparisonWidget/ChatPreviewComparisonWidget.d.ts +3 -3
  22. package/dist/widgets/ChatPreviewComparisonWidget/ChatPreviewComparisonWidget.js +3 -3
  23. package/dist/widgets/ChatPreviewLoadingWidget/ChatPreviewLoadingWidget.cjs +1 -1
  24. package/dist/widgets/ChatPreviewLoadingWidget/ChatPreviewLoadingWidget.d.cts +3 -3
  25. package/dist/widgets/ChatPreviewLoadingWidget/ChatPreviewLoadingWidget.d.ts +3 -3
  26. package/dist/widgets/ChatPreviewLoadingWidget/ChatPreviewLoadingWidget.js +1 -1
  27. package/dist/widgets/ChatPreviewWidget/ChatPreviewWidget.cjs +3 -3
  28. package/dist/widgets/ChatPreviewWidget/ChatPreviewWidget.d.ts +3 -3
  29. package/dist/widgets/ChatPreviewWidget/ChatPreviewWidget.js +3 -3
  30. package/dist/widgets/FloatingChatWidget/FloatingChatWidget.cjs +4 -4
  31. package/dist/widgets/FloatingChatWidget/FloatingChatWidget.d.cts +2 -2
  32. package/dist/widgets/FloatingChatWidget/FloatingChatWidget.d.ts +2 -2
  33. package/dist/widgets/FloatingChatWidget/FloatingChatWidget.js +4 -4
  34. package/dist/widgets/FloatingChatWidget/hooks/useAutoPopup.cjs +1 -1
  35. package/dist/widgets/FloatingChatWidget/hooks/useAutoPopup.js +1 -1
  36. package/dist/widgets/FloatingChatWidget/hooks/useFloatingButtonVisibility.cjs +1 -1
  37. package/dist/widgets/FloatingChatWidget/hooks/useFloatingButtonVisibility.js +1 -1
  38. package/dist/widgets/FullPageSalesAgentWidget/FullPageSalesAgentWidget.cjs +1 -1
  39. package/dist/widgets/FullPageSalesAgentWidget/FullPageSalesAgentWidget.d.cts +2 -2
  40. package/dist/widgets/FullPageSalesAgentWidget/FullPageSalesAgentWidget.d.ts +2 -2
  41. package/dist/widgets/FullPageSalesAgentWidget/FullPageSalesAgentWidget.js +1 -1
  42. package/dist/widgets/ProductCardWidget/ProductCardWidget.cjs +3 -3
  43. package/dist/widgets/ProductCardWidget/ProductCardWidget.d.cts +2 -2
  44. package/dist/widgets/ProductCardWidget/ProductCardWidget.d.ts +2 -2
  45. package/dist/widgets/ProductCardWidget/ProductCardWidget.js +3 -3
  46. package/dist/widgets/PromptButtonCarouselWithImageWidget/PromptButtonCarouselWithImageWidget.cjs +3 -3
  47. package/dist/widgets/PromptButtonCarouselWithImageWidget/PromptButtonCarouselWithImageWidget.d.cts +3 -3
  48. package/dist/widgets/PromptButtonCarouselWithImageWidget/PromptButtonCarouselWithImageWidget.d.ts +3 -3
  49. package/dist/widgets/PromptButtonCarouselWithImageWidget/PromptButtonCarouselWithImageWidget.js +3 -3
  50. package/dist/widgets/PromptCarouselWidget/PromptCarouselWidget.cjs +3 -3
  51. package/dist/widgets/PromptCarouselWidget/PromptCarouselWidget.d.ts +2 -2
  52. package/dist/widgets/PromptCarouselWidget/PromptCarouselWidget.js +3 -3
  53. package/dist/widgets/SocialProofFlowWidget/SocialProofFlowWidget.cjs +2 -2
  54. package/dist/widgets/SocialProofFlowWidget/SocialProofFlowWidget.d.ts +2 -2
  55. package/dist/widgets/SocialProofFlowWidget/SocialProofFlowWidget.js +2 -2
  56. package/dist/widgets/SocialProofWidget/SocialProofWidget.cjs +3 -3
  57. package/dist/widgets/SocialProofWidget/SocialProofWidget.d.cts +3 -3
  58. package/dist/widgets/SocialProofWidget/SocialProofWidget.d.ts +3 -3
  59. package/dist/widgets/SocialProofWidget/SocialProofWidget.js +3 -3
  60. package/dist/widgets/TitledPromptCarouselWidget/TitledPromptCarouselWidget.cjs +3 -3
  61. package/dist/widgets/TitledPromptCarouselWidget/TitledPromptCarouselWidget.d.cts +2 -2
  62. package/dist/widgets/TitledPromptCarouselWidget/TitledPromptCarouselWidget.d.ts +2 -2
  63. package/dist/widgets/TitledPromptCarouselWidget/TitledPromptCarouselWidget.js +3 -3
  64. package/dist/widgets/TypingAnimationFlowWidget/TypingAnimationFlowWidget.cjs +2 -2
  65. package/dist/widgets/TypingAnimationFlowWidget/TypingAnimationFlowWidget.d.cts +2 -2
  66. package/dist/widgets/TypingAnimationFlowWidget/TypingAnimationFlowWidget.d.ts +2 -2
  67. package/dist/widgets/TypingAnimationFlowWidget/TypingAnimationFlowWidget.js +2 -2
  68. package/dist/widgets/TypingAnimationWidget/TypingAnimationWidget.cjs +3 -3
  69. package/dist/widgets/TypingAnimationWidget/TypingAnimationWidget.d.cts +3 -3
  70. package/dist/widgets/TypingAnimationWidget/TypingAnimationWidget.d.ts +3 -3
  71. package/dist/widgets/TypingAnimationWidget/TypingAnimationWidget.js +3 -3
  72. package/dist/widgets/dist/SearchResults/SearchResultsWidget.d.cts +2 -2
  73. package/dist/widgets/dist/SearchZeroState/SearchZeroStateWidget.d.cts +2 -2
  74. package/dist/widgets/dist/SuggestionBar/SuggestionBar.d.cts +2 -2
  75. package/dist/widgets/hooks/useGetWidgetStatus.cjs +1 -1
  76. package/dist/widgets/hooks/useGetWidgetStatus.js +1 -1
  77. package/package.json +1 -1
  78. package/src/hocs/withBaseWidget/__tests__/withBaseWidget.test.tsx +76 -2
  79. package/src/hocs/withBaseWidget/withBaseWidget.tsx +42 -0
@@ -1,4 +1,4 @@
1
- import * as react_jsx_runtime0 from "react/jsx-runtime";
1
+ import * as react_jsx_runtime19 from "react/jsx-runtime";
2
2
 
3
3
  //#region src/widgets/TypingAnimationFlowWidget/TypingAnimationFlowWidget.d.ts
4
4
  interface TypingAnimationFlowWidgetProps {
@@ -7,7 +7,7 @@ interface TypingAnimationFlowWidgetProps {
7
7
  declare const TypingAnimationFlowWidget: {
8
8
  ({
9
9
  widgetConfigId
10
- }: TypingAnimationFlowWidgetProps): react_jsx_runtime0.JSX.Element;
10
+ }: TypingAnimationFlowWidgetProps): react_jsx_runtime19.JSX.Element;
11
11
  displayName: string;
12
12
  };
13
13
  //#endregion
@@ -1,10 +1,10 @@
1
1
  import { ChatPreviewLoadingWidgetWithBaseWidget } from "../ChatPreviewLoadingWidget/ChatPreviewLoadingWidget.js";
2
2
  import { ChatPreviewComparisonWidgetWithBaseWidget } from "../ChatPreviewComparisonWidget/ChatPreviewComparisonWidget.js";
3
- import { ChatPreviewWidgetWithBaseWidget } from "../ChatPreviewWidget/ChatPreviewWidget.js";
4
3
  import useGetWidgetStatus_default from "../hooks/useGetWidgetStatus.js";
4
+ import { ChatPreviewWidgetWithBaseWidget } from "../ChatPreviewWidget/ChatPreviewWidget.js";
5
5
  import { TypingAnimationWithBaseWidget } from "../TypingAnimationWidget/TypingAnimationWidget.js";
6
- import { jsx } from "react/jsx-runtime";
7
6
  import { WidgetTypeV3 } from "@envive-ai/react-hooks/contexts/typesV3";
7
+ import { jsx } from "react/jsx-runtime";
8
8
  import { ChatPreviewLoading } from "@envive-ai/react-toolkit-v3/ChatPreviewLoading";
9
9
 
10
10
  //#region src/widgets/TypingAnimationFlowWidget/TypingAnimationFlowWidget.tsx
@@ -2,17 +2,17 @@ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
2
  const require_withBaseWidget = require('../../hocs/withBaseWidget/withBaseWidget.cjs');
3
3
  require('../../hocs/withBaseWidget/index.cjs');
4
4
  const require_functions = require('../utils/functions.cjs');
5
- let react = require("react");
6
- let __envive_ai_react_hooks_contexts_amplitudeContext = require("@envive-ai/react-hooks/contexts/amplitudeContext");
7
- let react_jsx_runtime = require("react/jsx-runtime");
8
5
  let __envive_ai_react_hooks_contexts_salesAgentContext = require("@envive-ai/react-hooks/contexts/salesAgentContext");
9
6
  let __envive_ai_react_hooks_contexts_typesV3 = require("@envive-ai/react-hooks/contexts/typesV3");
10
7
  let __envive_ai_react_hooks_hooks_ChatToggle = require("@envive-ai/react-hooks/hooks/ChatToggle");
11
8
  let __envive_ai_react_hooks_contexts_featureFlagServiceContext = require("@envive-ai/react-hooks/contexts/featureFlagServiceContext");
12
9
  let __envive_ai_react_hooks_application_models = require("@envive-ai/react-hooks/application/models");
10
+ let __envive_ai_react_hooks_contexts_amplitudeContext = require("@envive-ai/react-hooks/contexts/amplitudeContext");
13
11
  let __envive_ai_react_hooks_hooks_WidgetInteraction = require("@envive-ai/react-hooks/hooks/WidgetInteraction");
14
12
  let __envive_ai_react_hooks_hooks_WidgetInteraction_types = require("@envive-ai/react-hooks/hooks/WidgetInteraction/types");
15
13
  let __envive_ai_react_toolkit_v3_PromptCarousel = require("@envive-ai/react-toolkit-v3/PromptCarousel");
14
+ let react = require("react");
15
+ let react_jsx_runtime = require("react/jsx-runtime");
16
16
  let __envive_ai_react_toolkit_v3_PromptButton_types = require("@envive-ai/react-toolkit-v3/PromptButton/types");
17
17
  let __envive_ai_react_toolkit_v3_TypingAnimation = require("@envive-ai/react-toolkit-v3/TypingAnimation");
18
18
  let __envive_ai_react_toolkit_v3_WidgetWrapper = require("@envive-ai/react-toolkit-v3/WidgetWrapper");
@@ -1,9 +1,9 @@
1
1
  import { BaseWidgetProps } from "../../hocs/withBaseWidget/types.cjs";
2
- import * as react_jsx_runtime6 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime3 from "react/jsx-runtime";
3
3
 
4
4
  //#region src/widgets/TypingAnimationWidget/TypingAnimationWidget.d.ts
5
5
  declare const TypingAnimationWithBaseWidget: {
6
- (props: BaseWidgetProps): react_jsx_runtime6.JSX.Element;
6
+ (props: BaseWidgetProps): react_jsx_runtime3.JSX.Element;
7
7
  displayName: string;
8
8
  };
9
9
  interface TypingAnimationWidgetProps {
@@ -12,7 +12,7 @@ interface TypingAnimationWidgetProps {
12
12
  declare const TypingAnimationWidget: {
13
13
  ({
14
14
  widgetConfigId
15
- }: TypingAnimationWidgetProps): react_jsx_runtime6.JSX.Element;
15
+ }: TypingAnimationWidgetProps): react_jsx_runtime3.JSX.Element;
16
16
  displayName: string;
17
17
  };
18
18
  //#endregion
@@ -1,9 +1,9 @@
1
1
  import { BaseWidgetProps } from "../../hocs/withBaseWidget/types.js";
2
- import * as react_jsx_runtime18 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime3 from "react/jsx-runtime";
3
3
 
4
4
  //#region src/widgets/TypingAnimationWidget/TypingAnimationWidget.d.ts
5
5
  declare const TypingAnimationWithBaseWidget: {
6
- (props: BaseWidgetProps): react_jsx_runtime18.JSX.Element;
6
+ (props: BaseWidgetProps): react_jsx_runtime3.JSX.Element;
7
7
  displayName: string;
8
8
  };
9
9
  interface TypingAnimationWidgetProps {
@@ -12,7 +12,7 @@ interface TypingAnimationWidgetProps {
12
12
  declare const TypingAnimationWidget: {
13
13
  ({
14
14
  widgetConfigId
15
- }: TypingAnimationWidgetProps): react_jsx_runtime18.JSX.Element;
15
+ }: TypingAnimationWidgetProps): react_jsx_runtime3.JSX.Element;
16
16
  displayName: string;
17
17
  };
18
18
  //#endregion
@@ -1,17 +1,17 @@
1
1
  import { withBaseWidget } from "../../hocs/withBaseWidget/withBaseWidget.js";
2
2
  import "../../hocs/withBaseWidget/index.js";
3
3
  import { getStringIdForText } from "../utils/functions.js";
4
- import { useCallback } from "react";
5
- import { EnviveMetricsEventName, useAmplitude } from "@envive-ai/react-hooks/contexts/amplitudeContext";
6
- import { jsx } from "react/jsx-runtime";
7
4
  import { useSalesAgent } from "@envive-ai/react-hooks/contexts/salesAgentContext";
8
5
  import { WidgetTypeV3 } from "@envive-ai/react-hooks/contexts/typesV3";
9
6
  import { useChatToggle } from "@envive-ai/react-hooks/hooks/ChatToggle";
10
7
  import { useFeatureFlagService } from "@envive-ai/react-hooks/contexts/featureFlagServiceContext";
11
8
  import { ChatElementDisplayLocationV3, FeatureGates } from "@envive-ai/react-hooks/application/models";
9
+ import { EnviveMetricsEventName, useAmplitude } from "@envive-ai/react-hooks/contexts/amplitudeContext";
12
10
  import { useWidgetInteraction } from "@envive-ai/react-hooks/hooks/WidgetInteraction";
13
11
  import { WidgetInteractionComponent, WidgetInteractionType } from "@envive-ai/react-hooks/hooks/WidgetInteraction/types";
14
12
  import { PromptCarouselRows, usePromptCarouselAnalytics } from "@envive-ai/react-toolkit-v3/PromptCarousel";
13
+ import { useCallback } from "react";
14
+ import { jsx } from "react/jsx-runtime";
15
15
  import { PromptButtonVariant } from "@envive-ai/react-toolkit-v3/PromptButton/types";
16
16
  import { TypingAnimation } from "@envive-ai/react-toolkit-v3/TypingAnimation";
17
17
  import { WidgetWrapperVariant } from "@envive-ai/react-toolkit-v3/WidgetWrapper";
@@ -1,8 +1,8 @@
1
- import * as react_jsx_runtime0 from "react/jsx-runtime";
1
+ import * as react_jsx_runtime1 from "react/jsx-runtime";
2
2
 
3
3
  //#region ../widgets/dist/SearchResults/SearchResultsWidget.d.ts
4
4
  //#region src/SearchResults/SearchResultsWidget.d.ts
5
- declare const SearchResultsWidget: () => react_jsx_runtime0.JSX.Element;
5
+ declare const SearchResultsWidget: () => react_jsx_runtime1.JSX.Element;
6
6
  //#endregion
7
7
 
8
8
  //#endregion
@@ -1,4 +1,4 @@
1
- import * as react_jsx_runtime3 from "react/jsx-runtime";
1
+ import * as react_jsx_runtime2 from "react/jsx-runtime";
2
2
 
3
3
  //#region ../widgets/dist/SearchZeroState/SearchZeroStateWidget.d.ts
4
4
  //#region src/SearchZeroState/SearchZeroStateWidget.d.ts
@@ -11,7 +11,7 @@ declare const SearchZeroStateWidget: ({
11
11
  initialIsOpen,
12
12
  widgetConfigId,
13
13
  entryPointRef
14
- }: SearchZeroStateWidgetProps) => react_jsx_runtime3.JSX.Element;
14
+ }: SearchZeroStateWidgetProps) => react_jsx_runtime2.JSX.Element;
15
15
  //#endregion
16
16
 
17
17
  //#endregion
@@ -1,5 +1,5 @@
1
1
  import { SuggestionBarLocationForMetrics } from "./types.cjs";
2
- import * as react_jsx_runtime2 from "react/jsx-runtime";
2
+ import * as react_jsx_runtime3 from "react/jsx-runtime";
3
3
  import { SuggestionButtonVariant } from "@envive-ai/react-hooks/contexts/types";
4
4
  import { Message } from "postcss";
5
5
 
@@ -30,7 +30,7 @@ declare function SuggestionBar({
30
30
  buttonBorderRadius,
31
31
  handleReply,
32
32
  dataTestId
33
- }: Readonly<SuggestionBarProps>): react_jsx_runtime2.JSX.Element;
33
+ }: Readonly<SuggestionBarProps>): react_jsx_runtime3.JSX.Element;
34
34
  //#endregion
35
35
  //#endregion
36
36
  export { SuggestionBar };
@@ -1,8 +1,8 @@
1
1
  const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
2
  const require_functions = require('../utils/functions.cjs');
3
- let react = require("react");
4
3
  let __envive_ai_react_hooks_atoms_chat = require("@envive-ai/react-hooks/atoms/chat");
5
4
  let jotai = require("jotai");
5
+ let react = require("react");
6
6
  let __envive_ai_react_hooks_atoms_chat_chatState = require("@envive-ai/react-hooks/atoms/chat/chatState");
7
7
 
8
8
  //#region src/widgets/hooks/useGetWidgetStatus.tsx
@@ -1,7 +1,7 @@
1
1
  import { isLoading, isProductComparison, userHasInteracted, userHasNotInteracted } from "../utils/functions.js";
2
- import { useMemo } from "react";
3
2
  import { chatAtom, lastAssistantMessageAtom } from "@envive-ai/react-hooks/atoms/chat";
4
3
  import { useAtomValue } from "jotai";
4
+ import { useMemo } from "react";
5
5
  import { responseStreamingAtom } from "@envive-ai/react-hooks/atoms/chat/chatState";
6
6
 
7
7
  //#region src/widgets/hooks/useGetWidgetStatus.tsx
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@envive-ai/react-widgets-v3",
3
- "version": "0.3.57",
3
+ "version": "0.3.59",
4
4
  "description": "React widget library v3 for Envive services.",
5
5
  "keywords": [
6
6
  "react",
@@ -1,12 +1,13 @@
1
- import { render, screen, waitFor } from '@testing-library/react';
1
+ import { act, render, screen, waitFor } from '@testing-library/react';
2
2
  import { RefObject } from 'react';
3
3
  import { HardcopyResponse } from '@envive-ai/react-hooks/contexts/hardcopyContext';
4
4
  import { WidgetTypeV3 } from '@envive-ai/react-hooks/contexts/typesV3';
5
5
  import { UserEvent, UserEventCategory } from '@spiffy-ai/commerce-api-client';
6
6
  import { BaseWidgetProps } from '../types';
7
- import { withBaseWidget } from '../withBaseWidget';
7
+ import { WIDGET_LOADING_WATCHDOG_MS, withBaseWidget } from '../withBaseWidget';
8
8
 
9
9
  // Mock the contexts
10
+ const { mockLogError } = vi.hoisted(() => ({ mockLogError: vi.fn() }));
10
11
  const mockTrackEvent = vi.fn();
11
12
  const mockGetHardcopy = vi.fn();
12
13
  const mockGetWidgetConfig = vi.fn();
@@ -29,6 +30,18 @@ vi.mock('@envive-ai/react-hooks/contexts/amplitudeContext', () => ({
29
30
  },
30
31
  }));
31
32
 
33
+ vi.mock('@envive-ai/react-hooks/application/logging', () => ({
34
+ default: class MockLogger {
35
+ logError = mockLogError;
36
+
37
+ logWarn = vi.fn();
38
+
39
+ logInfo = vi.fn();
40
+
41
+ logDebug = vi.fn();
42
+ },
43
+ }));
44
+
32
45
  vi.mock('@envive-ai/react-hooks/contexts/hardcopyContext', () => ({
33
46
  useHardcopy: () => ({
34
47
  getHardcopy: mockGetHardcopy,
@@ -469,6 +482,67 @@ describe('withBaseWidget', () => {
469
482
  expect(screen.getByTestId('hardcopy-content')).toBeInTheDocument();
470
483
  });
471
484
 
485
+ it('logs a watchdog error when the widget is still loading after the timeout', async () => {
486
+ vi.useFakeTimers();
487
+ try {
488
+ // Hardcopy never settles — the widget stays in its loading state
489
+ mockGetHardcopy.mockReturnValue(new Promise<HardcopyResponse>(() => {}));
490
+
491
+ const WrappedWidget = withBaseWidget(TestWidget);
492
+ render(
493
+ <WrappedWidget
494
+ widgetConfigId="test-config-watchdog"
495
+ widgetType={WidgetTypeV3.PromptCarouselV3}
496
+ />,
497
+ );
498
+
499
+ // Let the config fetches settle first so only hardcopy is still pending
500
+ await act(async () => {
501
+ await vi.advanceTimersByTimeAsync(0);
502
+ });
503
+ await act(async () => {
504
+ await vi.advanceTimersByTimeAsync(WIDGET_LOADING_WATCHDOG_MS);
505
+ });
506
+
507
+ expect(mockLogError).toHaveBeenCalledTimes(1);
508
+ const [message, , context] = mockLogError.mock.calls[0];
509
+ expect(message).toContain('still loading');
510
+ expect(context).toMatchObject({
511
+ widget_type: WidgetTypeV3.PromptCarouselV3,
512
+ widget_config_id: 'test-config-watchdog',
513
+ pending_requests: ['hardcopy'],
514
+ });
515
+ } finally {
516
+ vi.useRealTimers();
517
+ }
518
+ });
519
+
520
+ it('does not log a watchdog error when the widget settles before the timeout', async () => {
521
+ vi.useFakeTimers();
522
+ try {
523
+ const WrappedWidget = withBaseWidget(TestWidget);
524
+ render(
525
+ <WrappedWidget
526
+ widgetConfigId="test-config-watchdog-ok"
527
+ widgetType={WidgetTypeV3.PromptCarouselV3}
528
+ />,
529
+ );
530
+
531
+ // Let the mocked fetches resolve, then run past the watchdog deadline
532
+ await act(async () => {
533
+ await vi.advanceTimersByTimeAsync(0);
534
+ });
535
+ expect(screen.getByTestId('is-loading')).toHaveTextContent('false');
536
+ await act(async () => {
537
+ await vi.advanceTimersByTimeAsync(WIDGET_LOADING_WATCHDOG_MS * 2);
538
+ });
539
+
540
+ expect(mockLogError).not.toHaveBeenCalled();
541
+ } finally {
542
+ vi.useRealTimers();
543
+ }
544
+ });
545
+
472
546
  it('still settles and stops loading when its own requests fail', async () => {
473
547
  mockHardcopyLoading = true;
474
548
  mockGetHardcopy.mockRejectedValue(new Error('Failed to fetch hardcopy'));
@@ -1,5 +1,6 @@
1
1
  import { useEffect, useMemo, useRef, useState } from 'react';
2
2
 
3
+ import Logger from '@envive-ai/react-hooks/application/logging';
3
4
  import { useAmplitude } from '@envive-ai/react-hooks/contexts/amplitudeContext';
4
5
  import { useTrackComponentVisibleEvent } from '@envive-ai/react-hooks/hooks/TrackComponentVisibleEvent';
5
6
  import { HardcopyResponse, useHardcopy } from '@envive-ai/react-hooks/contexts/hardcopyContext';
@@ -9,6 +10,12 @@ import { OrgUIConfigV3, WidgetConfigV3 } from '@envive-ai/react-hooks/contexts/t
9
10
  import { useUiConfig } from '@envive-ai/react-hooks/contexts/uiConfigContext';
10
11
  import { BaseWidgetProps, WithBaseWidgetOptions } from './types';
11
12
 
13
+ const logger = new Logger('withBaseWidget');
14
+
15
+ // How long a widget may stay in its loading state after it starts fetching before we
16
+ // consider it stuck and log an error for external session tools to pick up.
17
+ export const WIDGET_LOADING_WATCHDOG_MS = 5000;
18
+
12
19
  export function withBaseWidget<P extends BaseWidgetProps>(
13
20
  Widget: React.ComponentType<P>,
14
21
  options?: WithBaseWidgetOptions,
@@ -67,6 +74,41 @@ export function withBaseWidget<P extends BaseWidgetProps>(
67
74
  return isVisible && !!widgetConfigId && !!widgetType;
68
75
  }, [isVisible, widgetConfigId, widgetType]);
69
76
 
77
+ // Watchdog: a widget that is still in its loading state this long after it started
78
+ // fetching is stuck (or on a very slow connection). Log a console error so session
79
+ // tools that capture the console (Quantum Metric, Datadog RUM) can count and segment
80
+ // these sessions. Mirror the settled flags through a ref so mid-flight settles don't
81
+ // restart the timer, while the log still reports which requests were pending.
82
+ const settledStateRef = useRef({ hardcopy: false, widgetConfig: false, uiConfig: false });
83
+ settledStateRef.current = {
84
+ hardcopy: hardcopySettled,
85
+ widgetConfig: widgetConfigSettled,
86
+ uiConfig: uiConfigSettled,
87
+ };
88
+ useEffect(() => {
89
+ if (!startLoading || ownRequestsSettled) {
90
+ return undefined;
91
+ }
92
+ const timer = setTimeout(() => {
93
+ const settled = settledStateRef.current;
94
+ logger.logError(
95
+ `Widget still loading ${WIDGET_LOADING_WATCHDOG_MS}ms after fetches started`,
96
+ undefined,
97
+ {
98
+ widget_type: widgetType,
99
+ widget_config_id: widgetConfigId,
100
+ pending_requests: Object.entries(settled)
101
+ .filter(([, isSettled]) => !isSettled)
102
+ .map(([name]) => name),
103
+ // Network Information API — Chromium/Android only, undefined on Safari
104
+ connection_type: (navigator as Navigator & { connection?: { effectiveType?: string } })
105
+ .connection?.effectiveType,
106
+ },
107
+ );
108
+ }, WIDGET_LOADING_WATCHDOG_MS);
109
+ return () => clearTimeout(timer);
110
+ }, [startLoading, ownRequestsSettled, widgetConfigId, widgetType]);
111
+
70
112
  useEffect(() => {
71
113
  if (!startLoading || hardcopyFetchedRef.current) {
72
114
  return;