chayns-api 3.1.1 → 3.1.2

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.
@@ -124,7 +124,7 @@ const ChaynsProvider = ({
124
124
  rootLayerRef.current = (0, _rootLayer.getOrInitRootChaynsHistoryLayer)(history === null || history === void 0 ? void 0 : history.url, history === null || history === void 0 ? void 0 : history.segmentCount).rootLayer;
125
125
  }
126
126
  const layer = (_ref2 = historyLayer !== null && historyLayer !== void 0 ? historyLayer : parentLayerRef.current) !== null && _ref2 !== void 0 ? _ref2 : rootLayerRef.current;
127
- if (typeof segmentCount === 'number' && layer.getSegmentCount() !== segmentCount) {
127
+ if (layer && typeof segmentCount === 'number' && layer.getSegmentCount() !== segmentCount) {
128
128
  layer.setSegmentCount(segmentCount);
129
129
  }
130
130
  setEffectiveLayer(layer);
@@ -306,7 +306,7 @@ class FrameWrapper {
306
306
  },
307
307
  getHistoryLayer: () => {
308
308
  if (!this._historyLayer) {
309
- throw new Error('[chaynsHistory] No history layer available. Ensure historyLayer prop is set on the parent HostIframe.');
309
+ return null;
310
310
  }
311
311
  return this._historyLayer;
312
312
  }
@@ -371,7 +371,10 @@ class FrameWrapper {
371
371
  }, {});
372
372
  const exposedHistory = exposed.history;
373
373
  if (exposedHistory) {
374
- const initialState = await exposedHistory.getInitialState();
374
+ let initialState = null;
375
+ try {
376
+ initialState = await exposedHistory.getInitialState();
377
+ } catch (ex) {}
375
378
  if (initialState) {
376
379
  this._historyLayer = new _FrameHistoryLayer.FrameHistoryLayer({
377
380
  setRoute: (route, opts) => exposedHistory.setRoute(route, opts),
@@ -116,7 +116,7 @@ const ChaynsProvider = ({
116
116
  rootLayerRef.current = getOrInitRootChaynsHistoryLayer(history === null || history === void 0 ? void 0 : history.url, history === null || history === void 0 ? void 0 : history.segmentCount).rootLayer;
117
117
  }
118
118
  const layer = (_ref2 = historyLayer !== null && historyLayer !== void 0 ? historyLayer : parentLayerRef.current) !== null && _ref2 !== void 0 ? _ref2 : rootLayerRef.current;
119
- if (typeof segmentCount === 'number' && layer.getSegmentCount() !== segmentCount) {
119
+ if (layer && typeof segmentCount === 'number' && layer.getSegmentCount() !== segmentCount) {
120
120
  layer.setSegmentCount(segmentCount);
121
121
  }
122
122
  setEffectiveLayer(layer);
@@ -302,7 +302,7 @@ export class FrameWrapper {
302
302
  },
303
303
  getHistoryLayer: () => {
304
304
  if (!this._historyLayer) {
305
- throw new Error('[chaynsHistory] No history layer available. Ensure historyLayer prop is set on the parent HostIframe.');
305
+ return null;
306
306
  }
307
307
  return this._historyLayer;
308
308
  }
@@ -375,7 +375,10 @@ export class FrameWrapper {
375
375
  }, {});
376
376
  const exposedHistory = exposed.history;
377
377
  if (exposedHistory) {
378
- const initialState = await exposedHistory.getInitialState();
378
+ let initialState = null;
379
+ try {
380
+ initialState = await exposedHistory.getInitialState();
381
+ } catch (ex) {}
379
382
  if (initialState) {
380
383
  this._historyLayer = new FrameHistoryLayer({
381
384
  setRoute: (route, opts) => exposedHistory.setRoute(route, opts),
@@ -467,7 +467,7 @@ export interface ChaynsReactFunctions {
467
467
  destination: string;
468
468
  isPermanent?: boolean;
469
469
  }) => Promise<void>;
470
- getHistoryLayer(): ChaynsHistoryLayer;
470
+ getHistoryLayer(): ChaynsHistoryLayer | null;
471
471
  }
472
472
  export type ChaynsReactCustomFunctions = {
473
473
  [key: string]: (...args: any[]) => Promise<any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chayns-api",
3
- "version": "3.1.1",
3
+ "version": "3.1.2",
4
4
  "description": "new chayns api",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",