@dloizides/ui-feedback 1.6.0 → 1.7.0

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,54 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.7.0
4
+
5
+ Closes the API gap that kept `kefi-web`, `erevna-web` and `katalogos-web` on their
6
+ local `ErrorBoundary` copies. Those three vary the boundary **by error class** — a
7
+ stale-chunk failure after a deploy needs different wording, no retry button, and no
8
+ stack dump — which 1.6.0's static `labels` / boolean `showDetails` could not express.
9
+ Every addition is opt-in; the pre-1.7.0 test suite passes unmodified.
10
+
11
+ **The kit still does not know what a "chunk" is.** Apps inject the classification;
12
+ the boundary only learns *whether retry is meaningful* and *what to say*.
13
+
14
+ - **Add `retryable?: (error) => boolean`.** When it returns `false` the retry action is
15
+ not rendered at all. Offering a button that re-renders straight back into the same
16
+ missing chunk is worse than offering nothing. Default: every error is retryable
17
+ (1.6.0 behaviour).
18
+ - **Add `labelsFor?: (error) => Partial<ErrorBoundaryLabels>`,** merged OVER the static
19
+ `labels`. Lets an app say "Update available" for a stale chunk without the kit knowing
20
+ why — it sees only the resulting strings.
21
+ - **Widen `showDetails` to `boolean | ((error) => boolean)`.** A predicate can suppress
22
+ the dev-only block per error class (a hashed filename is noise, not signal). **A plain
23
+ boolean behaves exactly as before.**
24
+ - **Add `onMount?: () => void`,** called from `componentDidMount` ONLY when the mount was
25
+ clean. The three apps release their one-shot reload guard here: a clean mount proves the
26
+ current chunks loaded, so a FUTURE deploy may auto-recover again. Deliberately not called
27
+ on an errored mount — that would re-arm the guard during the very failure it bounds.
28
+ - **Add `reloadIsPrimary?: boolean`** (default `false`). Gives Reload the filled emphasis
29
+ and the first position instead of Try Again.
30
+
31
+ **Why a flag rather than an unconditional swap:** `agora-web` and `zygos-web` both pass
32
+ `onReload`, so simply inverting the priority would have silently restyled and reordered
33
+ their error screens too. They have no chunk-recovery path, so retry is still the right
34
+ primary there. The default preserves their rendering exactly; the three chunk-aware apps
35
+ opt in.
36
+
37
+ **Notably, `DEFAULT_ERROR_BOUNDARY_LABELS` gains no `updateTitle`/`updateMessage`.** Those
38
+ are domain vocabulary — "an update is available" is a fact about the app's deploy model, not
39
+ about error boundaries. `labelsFor` supplies them as ordinary `title`/`message` overrides,
40
+ which keeps the kit's label bag domain-free.
41
+
42
+ ### Fixed
43
+
44
+ - **`AppErrorBoundary.test.tsx` had never actually run.** `jest.setup.ts` imports
45
+ `@testing-library/jest-dom`, which registers matchers at runtime, but `tsconfig.test.json`
46
+ listed no `types`, so ts-jest failed every `toBeInTheDocument()` with TS2339 and aborted the
47
+ whole suite at compile time. It was the only suite using those matchers, so `npm test`
48
+ reported a red SUITE while the other five stayed green and the true test count read 34.
49
+ Adding `"types": ["jest", "node", "@testing-library/jest-dom"]` brings its 14 assertions
50
+ online for the first time — unmodified, and passing against the 1.7.0 source.
51
+
3
52
  ## 1.6.0
4
53
 
5
54
  Two fleet-wide duplicates extracted (W1.2 + W1.3). Both are purely additive — every
package/dist/index.d.mts CHANGED
@@ -392,10 +392,48 @@ interface AppErrorBoundaryProps {
392
392
  * of the error screen. Return `false`/omit to fall through to the fallback.
393
393
  */
394
394
  recover?: (error: Error) => boolean;
395
- /** Render the error message in the fallback (dev-only stack). Default `false`. */
396
- showDetails?: boolean;
395
+ /**
396
+ * Render the error message in the fallback (dev-only stack). Default `false`.
397
+ *
398
+ * A predicate is asked per caught error, so an app can suppress the block for
399
+ * error classes where the stack is noise rather than signal (the three chunk-aware
400
+ * apps hide it for a stale-chunk failure: the message names a hashed filename the
401
+ * user can do nothing with). A plain boolean behaves exactly as it always has.
402
+ */
403
+ showDetails?: boolean | ((error: Error) => boolean);
397
404
  /** Pre-localized wording. Anything omitted falls back to the English defaults. */
398
405
  labels?: Partial<ErrorBoundaryLabels>;
406
+ /**
407
+ * Per-error wording, merged OVER `labels`. Lets a caller say something specific
408
+ * about a specific failure ("Update available" for a stale chunk) without the kit
409
+ * knowing why — it never sees the classification, only the resulting strings.
410
+ */
411
+ labelsFor?: (error: Error) => Partial<ErrorBoundaryLabels>;
412
+ /**
413
+ * Whether retrying could plausibly help. When this returns `false` the retry
414
+ * action is NOT rendered at all — offering a button that re-renders straight back
415
+ * into the same failure is worse than offering nothing. Default: every error is
416
+ * retryable, which is the behaviour before this prop existed.
417
+ */
418
+ retryable?: (error: Error) => boolean;
419
+ /**
420
+ * Called from `componentDidMount` ONLY when the mount was clean (nothing caught).
421
+ * The chunk-aware apps use it to release their one-shot reload guard: a clean mount
422
+ * proves the current chunks loaded, so a FUTURE deploy is allowed to auto-recover
423
+ * again. Deliberately NOT called on an errored mount — that would re-arm the guard
424
+ * during the very failure it is meant to bound, and reintroduce the reload loop.
425
+ */
426
+ onMount?: () => void;
427
+ /**
428
+ * Give the primary (filled) emphasis — and the first position — to **Reload**
429
+ * instead of **Try Again**. Default `false`, which preserves the emphasis every
430
+ * existing caller renders today.
431
+ *
432
+ * Apps with a stale-chunk failure mode set this: when the running bundle references
433
+ * a chunk that no longer exists, reloading is the action that actually works and
434
+ * re-rendering is the one that cannot.
435
+ */
436
+ reloadIsPrimary?: boolean;
399
437
  /** Prefix for every testID the boundary renders. Default `error-boundary`. */
400
438
  testIDPrefix?: string;
401
439
  /** Full escape hatch — replaces the built-in fallback entirely. */
@@ -415,6 +453,7 @@ interface AppErrorBoundaryState {
415
453
  declare class AppErrorBoundary extends Component<AppErrorBoundaryProps, AppErrorBoundaryState> {
416
454
  constructor(props: AppErrorBoundaryProps);
417
455
  static getDerivedStateFromError(error: Error): Partial<AppErrorBoundaryState>;
456
+ componentDidMount(): void;
418
457
  componentDidCatch(error: Error, info: ErrorInfo): void;
419
458
  private readonly handleRetry;
420
459
  render(): ReactNode;
package/dist/index.d.ts CHANGED
@@ -392,10 +392,48 @@ interface AppErrorBoundaryProps {
392
392
  * of the error screen. Return `false`/omit to fall through to the fallback.
393
393
  */
394
394
  recover?: (error: Error) => boolean;
395
- /** Render the error message in the fallback (dev-only stack). Default `false`. */
396
- showDetails?: boolean;
395
+ /**
396
+ * Render the error message in the fallback (dev-only stack). Default `false`.
397
+ *
398
+ * A predicate is asked per caught error, so an app can suppress the block for
399
+ * error classes where the stack is noise rather than signal (the three chunk-aware
400
+ * apps hide it for a stale-chunk failure: the message names a hashed filename the
401
+ * user can do nothing with). A plain boolean behaves exactly as it always has.
402
+ */
403
+ showDetails?: boolean | ((error: Error) => boolean);
397
404
  /** Pre-localized wording. Anything omitted falls back to the English defaults. */
398
405
  labels?: Partial<ErrorBoundaryLabels>;
406
+ /**
407
+ * Per-error wording, merged OVER `labels`. Lets a caller say something specific
408
+ * about a specific failure ("Update available" for a stale chunk) without the kit
409
+ * knowing why — it never sees the classification, only the resulting strings.
410
+ */
411
+ labelsFor?: (error: Error) => Partial<ErrorBoundaryLabels>;
412
+ /**
413
+ * Whether retrying could plausibly help. When this returns `false` the retry
414
+ * action is NOT rendered at all — offering a button that re-renders straight back
415
+ * into the same failure is worse than offering nothing. Default: every error is
416
+ * retryable, which is the behaviour before this prop existed.
417
+ */
418
+ retryable?: (error: Error) => boolean;
419
+ /**
420
+ * Called from `componentDidMount` ONLY when the mount was clean (nothing caught).
421
+ * The chunk-aware apps use it to release their one-shot reload guard: a clean mount
422
+ * proves the current chunks loaded, so a FUTURE deploy is allowed to auto-recover
423
+ * again. Deliberately NOT called on an errored mount — that would re-arm the guard
424
+ * during the very failure it is meant to bound, and reintroduce the reload loop.
425
+ */
426
+ onMount?: () => void;
427
+ /**
428
+ * Give the primary (filled) emphasis — and the first position — to **Reload**
429
+ * instead of **Try Again**. Default `false`, which preserves the emphasis every
430
+ * existing caller renders today.
431
+ *
432
+ * Apps with a stale-chunk failure mode set this: when the running bundle references
433
+ * a chunk that no longer exists, reloading is the action that actually works and
434
+ * re-rendering is the one that cannot.
435
+ */
436
+ reloadIsPrimary?: boolean;
399
437
  /** Prefix for every testID the boundary renders. Default `error-boundary`. */
400
438
  testIDPrefix?: string;
401
439
  /** Full escape hatch — replaces the built-in fallback entirely. */
@@ -415,6 +453,7 @@ interface AppErrorBoundaryState {
415
453
  declare class AppErrorBoundary extends Component<AppErrorBoundaryProps, AppErrorBoundaryState> {
416
454
  constructor(props: AppErrorBoundaryProps);
417
455
  static getDerivedStateFromError(error: Error): Partial<AppErrorBoundaryState>;
456
+ componentDidMount(): void;
418
457
  componentDidCatch(error: Error, info: ErrorInfo): void;
419
458
  private readonly handleRetry;
420
459
  render(): ReactNode;
package/dist/index.js CHANGED
@@ -825,6 +825,8 @@ var ErrorBoundaryFallback = ({
825
825
  testIDPrefix,
826
826
  error,
827
827
  showDetails,
828
+ showRetry,
829
+ reloadIsPrimary,
828
830
  onRetry,
829
831
  onReload
830
832
  }) => {
@@ -832,6 +834,34 @@ var ErrorBoundaryFallback = ({
832
834
  const warningColor = (theme.semantic.warning ?? theme.semantic.error)["500"];
833
835
  const primaryColor = theme.palette.primary["500"];
834
836
  const hasDetails = showDetails && error !== null;
837
+ const primaryFill = { backgroundColor: primaryColor };
838
+ const primaryInk = { color: theme.colors.surfaceElevated };
839
+ const secondaryFill = { backgroundColor: theme.colors.surface };
840
+ const secondaryInk = { color: theme.colors.text };
841
+ const retryButton = showRetry ? /* @__PURE__ */ jsxRuntime.jsx(
842
+ reactNative.TouchableOpacity,
843
+ {
844
+ accessibilityHint: labels.tryAgainHint,
845
+ accessibilityLabel: labels.tryAgain,
846
+ accessibilityRole: "button",
847
+ style: [styles8.button, reloadIsPrimary ? secondaryFill : primaryFill],
848
+ testID: `${testIDPrefix}-retry-button`,
849
+ onPress: onRetry,
850
+ children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles8.buttonText, reloadIsPrimary ? secondaryInk : primaryInk], children: labels.tryAgain })
851
+ }
852
+ ) : null;
853
+ const reloadButton = typeof onReload === "function" ? /* @__PURE__ */ jsxRuntime.jsx(
854
+ reactNative.TouchableOpacity,
855
+ {
856
+ accessibilityHint: labels.reloadHint,
857
+ accessibilityLabel: labels.reload,
858
+ accessibilityRole: "button",
859
+ style: [styles8.button, reloadIsPrimary ? primaryFill : secondaryFill],
860
+ testID: `${testIDPrefix}-reload-button`,
861
+ onPress: onReload,
862
+ children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles8.buttonText, reloadIsPrimary ? primaryInk : secondaryInk], children: labels.reload })
863
+ }
864
+ ) : null;
835
865
  return /* @__PURE__ */ jsxRuntime.jsx(
836
866
  reactNative.View,
837
867
  {
@@ -853,30 +883,8 @@ var ErrorBoundaryFallback = ({
853
883
  ]
854
884
  }
855
885
  ) : null,
856
- /* @__PURE__ */ jsxRuntime.jsx(
857
- reactNative.TouchableOpacity,
858
- {
859
- accessibilityHint: labels.tryAgainHint,
860
- accessibilityLabel: labels.tryAgain,
861
- accessibilityRole: "button",
862
- style: [styles8.button, { backgroundColor: primaryColor }],
863
- testID: `${testIDPrefix}-retry-button`,
864
- onPress: onRetry,
865
- children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles8.buttonText, { color: theme.colors.surfaceElevated }], children: labels.tryAgain })
866
- }
867
- ),
868
- typeof onReload === "function" ? /* @__PURE__ */ jsxRuntime.jsx(
869
- reactNative.TouchableOpacity,
870
- {
871
- accessibilityHint: labels.reloadHint,
872
- accessibilityLabel: labels.reload,
873
- accessibilityRole: "button",
874
- style: [styles8.button, { backgroundColor: theme.colors.surface }],
875
- testID: `${testIDPrefix}-reload-button`,
876
- onPress: onReload,
877
- children: /* @__PURE__ */ jsxRuntime.jsx(reactNative.Text, { style: [styles8.buttonText, { color: theme.colors.text }], children: labels.reload })
878
- }
879
- ) : null
886
+ reloadIsPrimary ? reloadButton : retryButton,
887
+ reloadIsPrimary ? retryButton : reloadButton
880
888
  ] })
881
889
  }
882
890
  );
@@ -928,6 +936,20 @@ var DEFAULT_ERROR_BOUNDARY_LABELS = {
928
936
  updating: "Updating\u2026",
929
937
  errorDetails: "Error details"
930
938
  };
939
+
940
+ // src/AppErrorBoundary/resolve.ts
941
+ function resolveLabels(labels, labelsFor, error) {
942
+ const perError = typeof labelsFor === "function" && error !== null ? labelsFor(error) : {};
943
+ return { ...DEFAULT_ERROR_BOUNDARY_LABELS, ...labels, ...perError };
944
+ }
945
+ function resolveShowDetails(showDetails, error) {
946
+ if (typeof showDetails === "function") return error !== null && showDetails(error);
947
+ return showDetails === true;
948
+ }
949
+ function resolveRetryable(retryable, error) {
950
+ if (typeof retryable !== "function" || error === null) return true;
951
+ return retryable(error);
952
+ }
931
953
  var INITIAL_STATE = { hasError: false, error: null, recovering: false };
932
954
  var AppErrorBoundary = class extends React3.Component {
933
955
  constructor(props) {
@@ -940,16 +962,20 @@ var AppErrorBoundary = class extends React3.Component {
940
962
  static getDerivedStateFromError(error) {
941
963
  return { hasError: true, error };
942
964
  }
965
+ componentDidMount() {
966
+ const isCleanMount = !this.state.hasError;
967
+ if (isCleanMount && typeof this.props.onMount === "function") this.props.onMount();
968
+ }
943
969
  componentDidCatch(error, info) {
944
970
  if (typeof this.props.onError === "function") this.props.onError(error, info);
945
971
  const isHandled = typeof this.props.recover === "function" && this.props.recover(error);
946
972
  if (isHandled) this.setState({ recovering: true });
947
973
  }
948
974
  render() {
949
- const { children, fallback, labels, showDetails = false, onReload } = this.props;
975
+ const { children, fallback, labels, labelsFor, showDetails, onReload } = this.props;
950
976
  const { hasError, error, recovering } = this.state;
951
977
  const testIDPrefix = this.props.testIDPrefix ?? FEEDBACK_TEST_IDS.errorBoundary;
952
- const resolvedLabels = { ...DEFAULT_ERROR_BOUNDARY_LABELS, ...labels };
978
+ const resolvedLabels = resolveLabels(labels, labelsFor, error);
953
979
  if (!hasError) return children;
954
980
  if (typeof fallback === "function") return fallback({ error, recovering, retry: this.handleRetry });
955
981
  if (recovering)
@@ -959,7 +985,9 @@ var AppErrorBoundary = class extends React3.Component {
959
985
  {
960
986
  error,
961
987
  labels: resolvedLabels,
962
- showDetails,
988
+ reloadIsPrimary: this.props.reloadIsPrimary === true,
989
+ showDetails: resolveShowDetails(showDetails, error),
990
+ showRetry: resolveRetryable(this.props.retryable, error),
963
991
  testIDPrefix,
964
992
  onReload,
965
993
  onRetry: this.handleRetry