@player-ui/react 0.15.3-next.3 → 0.15.4--canary.881.37421

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.
@@ -4,7 +4,11 @@ export * from "@player-ui/player";
4
4
  // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/player.tsx
5
5
  import React4 from "react";
6
6
  import { SyncWaterfallHook, AsyncParallelHook } from "tapable-ts";
7
- import { Subscribe, useSubscribedState } from "@player-ui/react-subscribe";
7
+ import {
8
+ Subscribe,
9
+ useSubscribedState,
10
+ useSubscriber
11
+ } from "@player-ui/react-subscribe";
8
12
  import { Registry } from "@player-ui/partial-match-registry";
9
13
  import { Player } from "@player-ui/player";
10
14
  import { ErrorBoundary as ErrorBoundary2 } from "react-error-boundary";
@@ -15,12 +19,21 @@ import leven from "leven";
15
19
  import { ErrorBoundary } from "react-error-boundary";
16
20
 
17
21
  // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/asset/AssetRenderError.ts
22
+ import {
23
+ ErrorSeverity,
24
+ ErrorTypes
25
+ } from "@player-ui/player";
18
26
  var AssetRenderError = class extends Error {
19
27
  constructor(rootAsset, message, innerException) {
20
28
  super(message);
21
29
  this.rootAsset = rootAsset;
22
30
  this.innerException = innerException;
23
31
  this.assetParentPath = [];
32
+ this.type = ErrorTypes.RENDER;
33
+ this.severity = ErrorSeverity.ERROR;
34
+ this.metadata = {
35
+ assetId: rootAsset.id
36
+ };
24
37
  this.initialMessage = message ?? "";
25
38
  this.innerExceptionMessage = innerException instanceof Error ? innerException.message : String(innerException);
26
39
  if (this.innerExceptionMessage) {
@@ -124,6 +137,7 @@ var ReactAsset = (props) => {
124
137
  error
125
138
  );
126
139
  }
140
+ return null;
127
141
  }
128
142
  },
129
143
  /* @__PURE__ */ React.createElement(Impl, { key: unwrapped.id, ...unwrapped })
@@ -241,6 +255,7 @@ var OnUpdatePlugin = class {
241
255
  };
242
256
 
243
257
  // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/player.tsx
258
+ var ReactPlayerPropsContext = React4.createContext({ isInErrorState: false });
244
259
  var _window = typeof window === "undefined" ? void 0 : window;
245
260
  var ReactPlayer2 = class {
246
261
  constructor(options) {
@@ -301,10 +316,16 @@ var ReactPlayer2 = class {
301
316
  }
302
317
  /** Register and apply [Plugin] if one with the same symbol is not already registered. */
303
318
  registerPlugin(plugin) {
304
- if (!plugin.applyReact)
305
- return;
306
- plugin.applyReact(this);
307
- this.options.plugins?.push(plugin);
319
+ if (plugin.apply) {
320
+ this.player.registerPlugin(plugin);
321
+ }
322
+ if (plugin.applyReact) {
323
+ plugin.applyReact?.(this);
324
+ }
325
+ if (!this.options.plugins) {
326
+ this.options.plugins = [];
327
+ }
328
+ this.options.plugins.push(plugin);
308
329
  }
309
330
  /**
310
331
  * Returns the current version of the running React Player
@@ -323,18 +344,84 @@ var ReactPlayer2 = class {
323
344
  createReactPlayerComponent() {
324
345
  const BaseComp = this.hooks.webComponent.call(this.createReactComp());
325
346
  const ReactPlayerComponent = (props) => {
347
+ const trackedErrors = React4.useRef(/* @__PURE__ */ new Map());
348
+ const [errorSubId, setErrorSubId] = React4.useState(
349
+ void 0
350
+ );
351
+ const { subscribe, unsubscribe } = useSubscriber(
352
+ this.viewUpdateSubscription
353
+ );
354
+ const componentProps = React4.useMemo(
355
+ () => ({
356
+ ...props,
357
+ isInErrorState: errorSubId !== void 0
358
+ }),
359
+ [props, errorSubId]
360
+ );
361
+ const clearErrorTracking = React4.useCallback(() => {
362
+ trackedErrors.current.clear();
363
+ setErrorSubId((prev) => {
364
+ if (prev !== void 0) {
365
+ unsubscribe(prev);
366
+ }
367
+ return void 0;
368
+ });
369
+ }, []);
370
+ React4.useEffect(() => {
371
+ return clearErrorTracking;
372
+ }, [clearErrorTracking]);
373
+ const captureError = React4.useCallback(
374
+ (err) => {
375
+ const playerState = this.player.getState();
376
+ if (playerState.status !== "in-progress") {
377
+ this.player.logger.warn(
378
+ `[ReactPlayer]: An error occurred during rendering but was ignored due to a change in the player state (current state: '${playerState.status}'). Error Details:`,
379
+ err
380
+ );
381
+ return false;
382
+ }
383
+ const currentError = trackedErrors.current.get(err);
384
+ if (currentError !== void 0) {
385
+ return currentError;
386
+ }
387
+ let isRecovering = false;
388
+ setErrorSubId((prev) => {
389
+ const subId = prev === void 0 ? subscribe(clearErrorTracking, {
390
+ initializeWithPreviousValue: false
391
+ }) : prev;
392
+ isRecovering = playerState.controllers.error.captureError(err);
393
+ trackedErrors.current.set(err, isRecovering);
394
+ if (!isRecovering) {
395
+ if (subId !== prev) {
396
+ unsubscribe(subId);
397
+ }
398
+ return prev;
399
+ }
400
+ return subId;
401
+ });
402
+ return isRecovering;
403
+ },
404
+ [errorSubId]
405
+ );
326
406
  return /* @__PURE__ */ React4.createElement(
327
407
  ErrorBoundary2,
328
408
  {
329
- fallbackRender: () => null,
330
- onError: (err) => {
331
- const playerState = this.player.getState();
332
- if (playerState.status === "in-progress") {
333
- playerState.fail(err);
409
+ fallbackRender: (fallbackProps) => {
410
+ const isRecovering = captureError(fallbackProps.error);
411
+ if (!isRecovering) {
412
+ return null;
334
413
  }
414
+ fallbackProps.resetErrorBoundary();
415
+ return /* @__PURE__ */ React4.createElement(
416
+ ReactPlayerPropsContext.Provider,
417
+ {
418
+ value: { ...componentProps, isInErrorState: true }
419
+ },
420
+ /* @__PURE__ */ React4.createElement(PlayerContext.Provider, { value: { player: this.player } }, /* @__PURE__ */ React4.createElement(BaseComp, { ...componentProps, isInErrorState: true }))
421
+ );
335
422
  }
336
423
  },
337
- /* @__PURE__ */ React4.createElement(PlayerContext.Provider, { value: { player: this.player } }, /* @__PURE__ */ React4.createElement(BaseComp, { ...props }))
424
+ /* @__PURE__ */ React4.createElement(ReactPlayerPropsContext.Provider, { value: { ...componentProps } }, /* @__PURE__ */ React4.createElement(PlayerContext.Provider, { value: { player: this.player } }, /* @__PURE__ */ React4.createElement(BaseComp, { ...componentProps })))
338
425
  );
339
426
  };
340
427
  return ReactPlayerComponent;
@@ -342,8 +429,16 @@ var ReactPlayer2 = class {
342
429
  createReactComp() {
343
430
  const ActualPlayerComp = this.hooks.playerComponent.call(ReactPlayer);
344
431
  const WebPlayerComponent = () => {
432
+ const { isInErrorState } = React4.useContext(ReactPlayerPropsContext);
345
433
  const view = useSubscribedState(this.viewUpdateSubscription);
434
+ const lastSuccessfulView = React4.useRef(void 0);
346
435
  this.viewUpdateSubscription.suspend();
436
+ React4.useEffect(() => {
437
+ if (!isInErrorState) {
438
+ lastSuccessfulView.current = view;
439
+ }
440
+ }, [isInErrorState, view]);
441
+ const displayedView = isInErrorState ? lastSuccessfulView.current : view;
347
442
  return /* @__PURE__ */ React4.createElement(
348
443
  AssetContext.Provider,
349
444
  {
@@ -351,7 +446,7 @@ var ReactPlayer2 = class {
351
446
  registry: this.assetRegistry
352
447
  }
353
448
  },
354
- view && /* @__PURE__ */ React4.createElement(ActualPlayerComp, { view })
449
+ displayedView && /* @__PURE__ */ React4.createElement(ActualPlayerComp, { view: displayedView })
355
450
  );
356
451
  };
357
452
  return WebPlayerComponent;
@@ -626,9 +721,7 @@ var usePersistentStateMachine = (options) => {
626
721
  if (oldManagedState) {
627
722
  const playerState = oldManagedState.state?.context.reactPlayer.player.getState();
628
723
  if (oldManagedState.state?.value === "running" && playerState?.status === "in-progress") {
629
- previousManager.current.terminate?.(
630
- playerState.controllers.data.serialize()
631
- );
724
+ previousManager.current.terminate?.(playerState);
632
725
  }
633
726
  }
634
727
  const newKey = createKey();
@@ -685,7 +778,7 @@ var ManagedPlayer = (props) => {
685
778
  } else if (state?.value === "error") {
686
779
  props.onError?.(state?.context.error);
687
780
  } else if (state?.value === "running") {
688
- props.onStartedFlow?.();
781
+ props.onStartedFlow?.(state.context.flow);
689
782
  }
690
783
  }
691
784
  previousState.current = state;
@@ -693,7 +786,7 @@ var ManagedPlayer = (props) => {
693
786
  return () => {
694
787
  const playerState = state?.context.reactPlayer.player.getState();
695
788
  if (state?.value === "running" && playerState?.status === "in-progress") {
696
- props.manager.terminate?.(playerState.controllers.data.serialize());
789
+ props.manager.terminate?.(playerState);
697
790
  }
698
791
  };
699
792
  }, [props.manager, state?.context.reactPlayer.player, state?.value]);
@@ -729,6 +822,7 @@ export {
729
822
  PlayerContext,
730
823
  ReactAsset,
731
824
  ReactPlayer2 as ReactPlayer,
825
+ ReactPlayerPropsContext,
732
826
  WebPlayer,
733
827
  buildUrl,
734
828
  callOrReturn,
package/dist/index.mjs CHANGED
@@ -4,7 +4,11 @@ export * from "@player-ui/player";
4
4
  // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/player.tsx
5
5
  import React4 from "react";
6
6
  import { SyncWaterfallHook, AsyncParallelHook } from "tapable-ts";
7
- import { Subscribe, useSubscribedState } from "@player-ui/react-subscribe";
7
+ import {
8
+ Subscribe,
9
+ useSubscribedState,
10
+ useSubscriber
11
+ } from "@player-ui/react-subscribe";
8
12
  import { Registry } from "@player-ui/partial-match-registry";
9
13
  import { Player } from "@player-ui/player";
10
14
  import { ErrorBoundary as ErrorBoundary2 } from "react-error-boundary";
@@ -15,12 +19,21 @@ import leven from "leven";
15
19
  import { ErrorBoundary } from "react-error-boundary";
16
20
 
17
21
  // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/asset/AssetRenderError.ts
22
+ import {
23
+ ErrorSeverity,
24
+ ErrorTypes
25
+ } from "@player-ui/player";
18
26
  var AssetRenderError = class extends Error {
19
27
  constructor(rootAsset, message, innerException) {
20
28
  super(message);
21
29
  this.rootAsset = rootAsset;
22
30
  this.innerException = innerException;
23
31
  this.assetParentPath = [];
32
+ this.type = ErrorTypes.RENDER;
33
+ this.severity = ErrorSeverity.ERROR;
34
+ this.metadata = {
35
+ assetId: rootAsset.id
36
+ };
24
37
  this.initialMessage = message ?? "";
25
38
  this.innerExceptionMessage = innerException instanceof Error ? innerException.message : String(innerException);
26
39
  if (this.innerExceptionMessage) {
@@ -124,6 +137,7 @@ var ReactAsset = (props) => {
124
137
  error
125
138
  );
126
139
  }
140
+ return null;
127
141
  }
128
142
  },
129
143
  /* @__PURE__ */ React.createElement(Impl, { key: unwrapped.id, ...unwrapped })
@@ -241,6 +255,7 @@ var OnUpdatePlugin = class {
241
255
  };
242
256
 
243
257
  // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/react/player/src/player.tsx
258
+ var ReactPlayerPropsContext = React4.createContext({ isInErrorState: false });
244
259
  var _window = typeof window === "undefined" ? void 0 : window;
245
260
  var ReactPlayer2 = class {
246
261
  constructor(options) {
@@ -301,10 +316,16 @@ var ReactPlayer2 = class {
301
316
  }
302
317
  /** Register and apply [Plugin] if one with the same symbol is not already registered. */
303
318
  registerPlugin(plugin) {
304
- if (!plugin.applyReact)
305
- return;
306
- plugin.applyReact(this);
307
- this.options.plugins?.push(plugin);
319
+ if (plugin.apply) {
320
+ this.player.registerPlugin(plugin);
321
+ }
322
+ if (plugin.applyReact) {
323
+ plugin.applyReact?.(this);
324
+ }
325
+ if (!this.options.plugins) {
326
+ this.options.plugins = [];
327
+ }
328
+ this.options.plugins.push(plugin);
308
329
  }
309
330
  /**
310
331
  * Returns the current version of the running React Player
@@ -323,18 +344,84 @@ var ReactPlayer2 = class {
323
344
  createReactPlayerComponent() {
324
345
  const BaseComp = this.hooks.webComponent.call(this.createReactComp());
325
346
  const ReactPlayerComponent = (props) => {
347
+ const trackedErrors = React4.useRef(/* @__PURE__ */ new Map());
348
+ const [errorSubId, setErrorSubId] = React4.useState(
349
+ void 0
350
+ );
351
+ const { subscribe, unsubscribe } = useSubscriber(
352
+ this.viewUpdateSubscription
353
+ );
354
+ const componentProps = React4.useMemo(
355
+ () => ({
356
+ ...props,
357
+ isInErrorState: errorSubId !== void 0
358
+ }),
359
+ [props, errorSubId]
360
+ );
361
+ const clearErrorTracking = React4.useCallback(() => {
362
+ trackedErrors.current.clear();
363
+ setErrorSubId((prev) => {
364
+ if (prev !== void 0) {
365
+ unsubscribe(prev);
366
+ }
367
+ return void 0;
368
+ });
369
+ }, []);
370
+ React4.useEffect(() => {
371
+ return clearErrorTracking;
372
+ }, [clearErrorTracking]);
373
+ const captureError = React4.useCallback(
374
+ (err) => {
375
+ const playerState = this.player.getState();
376
+ if (playerState.status !== "in-progress") {
377
+ this.player.logger.warn(
378
+ `[ReactPlayer]: An error occurred during rendering but was ignored due to a change in the player state (current state: '${playerState.status}'). Error Details:`,
379
+ err
380
+ );
381
+ return false;
382
+ }
383
+ const currentError = trackedErrors.current.get(err);
384
+ if (currentError !== void 0) {
385
+ return currentError;
386
+ }
387
+ let isRecovering = false;
388
+ setErrorSubId((prev) => {
389
+ const subId = prev === void 0 ? subscribe(clearErrorTracking, {
390
+ initializeWithPreviousValue: false
391
+ }) : prev;
392
+ isRecovering = playerState.controllers.error.captureError(err);
393
+ trackedErrors.current.set(err, isRecovering);
394
+ if (!isRecovering) {
395
+ if (subId !== prev) {
396
+ unsubscribe(subId);
397
+ }
398
+ return prev;
399
+ }
400
+ return subId;
401
+ });
402
+ return isRecovering;
403
+ },
404
+ [errorSubId]
405
+ );
326
406
  return /* @__PURE__ */ React4.createElement(
327
407
  ErrorBoundary2,
328
408
  {
329
- fallbackRender: () => null,
330
- onError: (err) => {
331
- const playerState = this.player.getState();
332
- if (playerState.status === "in-progress") {
333
- playerState.fail(err);
409
+ fallbackRender: (fallbackProps) => {
410
+ const isRecovering = captureError(fallbackProps.error);
411
+ if (!isRecovering) {
412
+ return null;
334
413
  }
414
+ fallbackProps.resetErrorBoundary();
415
+ return /* @__PURE__ */ React4.createElement(
416
+ ReactPlayerPropsContext.Provider,
417
+ {
418
+ value: { ...componentProps, isInErrorState: true }
419
+ },
420
+ /* @__PURE__ */ React4.createElement(PlayerContext.Provider, { value: { player: this.player } }, /* @__PURE__ */ React4.createElement(BaseComp, { ...componentProps, isInErrorState: true }))
421
+ );
335
422
  }
336
423
  },
337
- /* @__PURE__ */ React4.createElement(PlayerContext.Provider, { value: { player: this.player } }, /* @__PURE__ */ React4.createElement(BaseComp, { ...props }))
424
+ /* @__PURE__ */ React4.createElement(ReactPlayerPropsContext.Provider, { value: { ...componentProps } }, /* @__PURE__ */ React4.createElement(PlayerContext.Provider, { value: { player: this.player } }, /* @__PURE__ */ React4.createElement(BaseComp, { ...componentProps })))
338
425
  );
339
426
  };
340
427
  return ReactPlayerComponent;
@@ -342,8 +429,16 @@ var ReactPlayer2 = class {
342
429
  createReactComp() {
343
430
  const ActualPlayerComp = this.hooks.playerComponent.call(ReactPlayer);
344
431
  const WebPlayerComponent = () => {
432
+ const { isInErrorState } = React4.useContext(ReactPlayerPropsContext);
345
433
  const view = useSubscribedState(this.viewUpdateSubscription);
434
+ const lastSuccessfulView = React4.useRef(void 0);
346
435
  this.viewUpdateSubscription.suspend();
436
+ React4.useEffect(() => {
437
+ if (!isInErrorState) {
438
+ lastSuccessfulView.current = view;
439
+ }
440
+ }, [isInErrorState, view]);
441
+ const displayedView = isInErrorState ? lastSuccessfulView.current : view;
347
442
  return /* @__PURE__ */ React4.createElement(
348
443
  AssetContext.Provider,
349
444
  {
@@ -351,7 +446,7 @@ var ReactPlayer2 = class {
351
446
  registry: this.assetRegistry
352
447
  }
353
448
  },
354
- view && /* @__PURE__ */ React4.createElement(ActualPlayerComp, { view })
449
+ displayedView && /* @__PURE__ */ React4.createElement(ActualPlayerComp, { view: displayedView })
355
450
  );
356
451
  };
357
452
  return WebPlayerComponent;
@@ -626,9 +721,7 @@ var usePersistentStateMachine = (options) => {
626
721
  if (oldManagedState) {
627
722
  const playerState = oldManagedState.state?.context.reactPlayer.player.getState();
628
723
  if (oldManagedState.state?.value === "running" && playerState?.status === "in-progress") {
629
- previousManager.current.terminate?.(
630
- playerState.controllers.data.serialize()
631
- );
724
+ previousManager.current.terminate?.(playerState);
632
725
  }
633
726
  }
634
727
  const newKey = createKey();
@@ -685,7 +778,7 @@ var ManagedPlayer = (props) => {
685
778
  } else if (state?.value === "error") {
686
779
  props.onError?.(state?.context.error);
687
780
  } else if (state?.value === "running") {
688
- props.onStartedFlow?.();
781
+ props.onStartedFlow?.(state.context.flow);
689
782
  }
690
783
  }
691
784
  previousState.current = state;
@@ -693,7 +786,7 @@ var ManagedPlayer = (props) => {
693
786
  return () => {
694
787
  const playerState = state?.context.reactPlayer.player.getState();
695
788
  if (state?.value === "running" && playerState?.status === "in-progress") {
696
- props.manager.terminate?.(playerState.controllers.data.serialize());
789
+ props.manager.terminate?.(playerState);
697
790
  }
698
791
  };
699
792
  }, [props.manager, state?.context.reactPlayer.player, state?.value]);
@@ -729,6 +822,7 @@ export {
729
822
  PlayerContext,
730
823
  ReactAsset,
731
824
  ReactPlayer2 as ReactPlayer,
825
+ ReactPlayerPropsContext,
732
826
  WebPlayer,
733
827
  buildUrl,
734
828
  callOrReturn,