@tinkoff/router 0.5.115 → 0.6.102

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 (44) hide show
  1. package/lib/components/react/context.d.ts +1 -0
  2. package/lib/components/react/providers/transitions.browser.js +14 -3
  3. package/lib/components/react/providers/transitions.es.js +14 -3
  4. package/lib/components/react/providers/transitions.js +14 -3
  5. package/lib/components/react/useViewTransition.browser.js +9 -3
  6. package/lib/components/react/useViewTransition.d.ts +6 -1
  7. package/lib/components/react/useViewTransition.es.js +9 -3
  8. package/lib/components/react/useViewTransition.js +9 -3
  9. package/lib/history/base.browser.js +3 -0
  10. package/lib/history/base.d.ts +14 -1
  11. package/lib/history/base.es.js +3 -0
  12. package/lib/history/base.js +3 -0
  13. package/lib/history/client.browser.js +22 -2
  14. package/lib/history/client.d.ts +4 -8
  15. package/lib/history/client.es.js +22 -2
  16. package/lib/history/client.js +22 -2
  17. package/lib/history/server.d.ts +1 -0
  18. package/lib/history/server.es.js +7 -0
  19. package/lib/history/server.js +7 -0
  20. package/lib/history/wrapper.browser.js +8 -3
  21. package/lib/history/wrapper.d.ts +2 -1
  22. package/lib/history/wrapper.es.js +8 -3
  23. package/lib/history/wrapper.js +8 -3
  24. package/lib/router/abstract.browser.js +38 -13
  25. package/lib/router/abstract.d.ts +1 -0
  26. package/lib/router/abstract.es.js +38 -13
  27. package/lib/router/abstract.js +38 -13
  28. package/lib/router/browser.browser.js +67 -26
  29. package/lib/router/browser.d.ts +3 -1
  30. package/lib/router/client.browser.js +9 -4
  31. package/lib/router/client.d.ts +1 -0
  32. package/lib/router/client.es.js +9 -4
  33. package/lib/router/client.js +9 -4
  34. package/lib/router/constants.browser.js +6 -0
  35. package/lib/router/constants.d.ts +5 -0
  36. package/lib/router/constants.es.js +6 -0
  37. package/lib/router/constants.js +10 -0
  38. package/lib/router/server.es.js +3 -1
  39. package/lib/router/server.js +3 -1
  40. package/lib/tree/tree.browser.js +1 -0
  41. package/lib/tree/tree.es.js +1 -0
  42. package/lib/tree/tree.js +1 -0
  43. package/lib/types.d.ts +17 -1
  44. package/package.json +7 -7
@@ -10,6 +10,7 @@ export type ViewTransitionState = {
10
10
  isTransitioning: true;
11
11
  currentRoute: NavigationRoute;
12
12
  nextRoute: NavigationRoute;
13
+ types?: string[];
13
14
  };
14
15
  export declare const ViewTransitionContext: import("react").Context<ViewTransitionState>;
15
16
  //# sourceMappingURL=context.d.ts.map
@@ -36,6 +36,7 @@ const TransitionsProvider = ({ router, children, }) => {
36
36
  isTransitioning: true,
37
37
  currentRoute: navigation.from,
38
38
  nextRoute: navigation.to,
39
+ types: navigation.viewTransitionTypes,
39
40
  });
40
41
  return;
41
42
  }
@@ -56,12 +57,22 @@ const TransitionsProvider = ({ router, children, }) => {
56
57
  // eslint-disable-next-line react-hooks/rules-of-hooks
57
58
  useEffect(() => {
58
59
  if (renderDeferred !== null && pendingState !== null) {
59
- const transition = document.startViewTransition(async () => {
60
+ const update = async () => {
60
61
  startReactTransition(() => {
61
62
  setState(pendingState);
62
63
  });
63
64
  await renderDeferred.promise;
64
- });
65
+ };
66
+ let transition;
67
+ if (window.ViewTransition && 'types' in window.ViewTransition.prototype) {
68
+ transition = document.startViewTransition({
69
+ update,
70
+ types: viewTransitionState.isTransitioning ? viewTransitionState.types : undefined,
71
+ });
72
+ }
73
+ else {
74
+ transition = document.startViewTransition(update);
75
+ }
65
76
  // eslint-disable-next-line promise/catch-or-return
66
77
  transition.finished.finally(() => {
67
78
  setRenderDeferred(null);
@@ -69,7 +80,7 @@ const TransitionsProvider = ({ router, children, }) => {
69
80
  setViewTransitionState({ isTransitioning: false });
70
81
  });
71
82
  }
72
- }, [pendingState, renderDeferred]);
83
+ }, [pendingState, renderDeferred, viewTransitionState]);
73
84
  // eslint-disable-next-line react-hooks/rules-of-hooks
74
85
  useEffect(() => {
75
86
  if (renderDeferred !== null &&
@@ -36,6 +36,7 @@ const TransitionsProvider = ({ router, children, }) => {
36
36
  isTransitioning: true,
37
37
  currentRoute: navigation.from,
38
38
  nextRoute: navigation.to,
39
+ types: navigation.viewTransitionTypes,
39
40
  });
40
41
  return;
41
42
  }
@@ -56,12 +57,22 @@ const TransitionsProvider = ({ router, children, }) => {
56
57
  // eslint-disable-next-line react-hooks/rules-of-hooks
57
58
  useEffect(() => {
58
59
  if (renderDeferred !== null && pendingState !== null) {
59
- const transition = document.startViewTransition(async () => {
60
+ const update = async () => {
60
61
  startReactTransition(() => {
61
62
  setState(pendingState);
62
63
  });
63
64
  await renderDeferred.promise;
64
- });
65
+ };
66
+ let transition;
67
+ if (window.ViewTransition && 'types' in window.ViewTransition.prototype) {
68
+ transition = document.startViewTransition({
69
+ update,
70
+ types: viewTransitionState.isTransitioning ? viewTransitionState.types : undefined,
71
+ });
72
+ }
73
+ else {
74
+ transition = document.startViewTransition(update);
75
+ }
65
76
  // eslint-disable-next-line promise/catch-or-return
66
77
  transition.finished.finally(() => {
67
78
  setRenderDeferred(null);
@@ -69,7 +80,7 @@ const TransitionsProvider = ({ router, children, }) => {
69
80
  setViewTransitionState({ isTransitioning: false });
70
81
  });
71
82
  }
72
- }, [pendingState, renderDeferred]);
83
+ }, [pendingState, renderDeferred, viewTransitionState]);
73
84
  // eslint-disable-next-line react-hooks/rules-of-hooks
74
85
  useEffect(() => {
75
86
  if (renderDeferred !== null &&
@@ -40,6 +40,7 @@ const TransitionsProvider = ({ router, children, }) => {
40
40
  isTransitioning: true,
41
41
  currentRoute: navigation.from,
42
42
  nextRoute: navigation.to,
43
+ types: navigation.viewTransitionTypes,
43
44
  });
44
45
  return;
45
46
  }
@@ -60,12 +61,22 @@ const TransitionsProvider = ({ router, children, }) => {
60
61
  // eslint-disable-next-line react-hooks/rules-of-hooks
61
62
  react.useEffect(() => {
62
63
  if (renderDeferred !== null && pendingState !== null) {
63
- const transition = document.startViewTransition(async () => {
64
+ const update = async () => {
64
65
  startReactTransition(() => {
65
66
  setState(pendingState);
66
67
  });
67
68
  await renderDeferred.promise;
68
- });
69
+ };
70
+ let transition;
71
+ if (window.ViewTransition && 'types' in window.ViewTransition.prototype) {
72
+ transition = document.startViewTransition({
73
+ update,
74
+ types: viewTransitionState.isTransitioning ? viewTransitionState.types : undefined,
75
+ });
76
+ }
77
+ else {
78
+ transition = document.startViewTransition(update);
79
+ }
69
80
  // eslint-disable-next-line promise/catch-or-return
70
81
  transition.finished.finally(() => {
71
82
  setRenderDeferred(null);
@@ -73,7 +84,7 @@ const TransitionsProvider = ({ router, children, }) => {
73
84
  setViewTransitionState({ isTransitioning: false });
74
85
  });
75
86
  }
76
- }, [pendingState, renderDeferred]);
87
+ }, [pendingState, renderDeferred, viewTransitionState]);
77
88
  // eslint-disable-next-line react-hooks/rules-of-hooks
78
89
  react.useEffect(() => {
79
90
  if (renderDeferred !== null &&
@@ -1,5 +1,6 @@
1
1
  import { useContext } from 'react';
2
2
  import { ViewTransitionContext, RouterContext } from './context.browser.js';
3
+ import { NAVIGATION_TYPE } from '../../router/constants.browser.js';
3
4
 
4
5
  const normalizePath = (payload, router) => {
5
6
  const route = router.resolve(payload);
@@ -13,10 +14,15 @@ const useViewTransition = (payload) => {
13
14
  const path = normalizePath(payload, router);
14
15
  const currentPath = viewTransition.currentRoute.actualPath;
15
16
  const nextPath = viewTransition.nextRoute.actualPath;
16
- // We are handling forward and back navigations for the same route here
17
- return [currentPath, nextPath].includes(path);
17
+ return {
18
+ // We are handling forward and back navigations for the same route here
19
+ isTransitioning: [currentPath, nextPath].includes(path),
20
+ types: viewTransition.types,
21
+ isForward: viewTransition.types.includes(NAVIGATION_TYPE.FORWARD),
22
+ isBack: viewTransition.types.includes(NAVIGATION_TYPE.BACK),
23
+ };
18
24
  }
19
- return false;
25
+ return { isTransitioning: false, isForward: false, isBack: false };
20
26
  };
21
27
 
22
28
  export { useViewTransition };
@@ -1,5 +1,10 @@
1
1
  import type { NavigateOptions } from '../../types';
2
2
  type Payload = string | Partial<NavigateOptions>;
3
- export declare const useViewTransition: (payload: Payload) => boolean;
3
+ export declare const useViewTransition: (payload: Payload) => {
4
+ isTransitioning: boolean;
5
+ types?: string[];
6
+ isForward: boolean;
7
+ isBack: boolean;
8
+ };
4
9
  export {};
5
10
  //# sourceMappingURL=useViewTransition.d.ts.map
@@ -1,5 +1,6 @@
1
1
  import { useContext } from 'react';
2
2
  import { ViewTransitionContext, RouterContext } from './context.es.js';
3
+ import { NAVIGATION_TYPE } from '../../router/constants.es.js';
3
4
 
4
5
  const normalizePath = (payload, router) => {
5
6
  const route = router.resolve(payload);
@@ -13,10 +14,15 @@ const useViewTransition = (payload) => {
13
14
  const path = normalizePath(payload, router);
14
15
  const currentPath = viewTransition.currentRoute.actualPath;
15
16
  const nextPath = viewTransition.nextRoute.actualPath;
16
- // We are handling forward and back navigations for the same route here
17
- return [currentPath, nextPath].includes(path);
17
+ return {
18
+ // We are handling forward and back navigations for the same route here
19
+ isTransitioning: [currentPath, nextPath].includes(path),
20
+ types: viewTransition.types,
21
+ isForward: viewTransition.types.includes(NAVIGATION_TYPE.FORWARD),
22
+ isBack: viewTransition.types.includes(NAVIGATION_TYPE.BACK),
23
+ };
18
24
  }
19
- return false;
25
+ return { isTransitioning: false, isForward: false, isBack: false };
20
26
  };
21
27
 
22
28
  export { useViewTransition };
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var react = require('react');
6
6
  var context = require('./context.js');
7
+ var constants = require('../../router/constants.js');
7
8
 
8
9
  const normalizePath = (payload, router) => {
9
10
  const route = router.resolve(payload);
@@ -17,10 +18,15 @@ const useViewTransition = (payload) => {
17
18
  const path = normalizePath(payload, router);
18
19
  const currentPath = viewTransition.currentRoute.actualPath;
19
20
  const nextPath = viewTransition.nextRoute.actualPath;
20
- // We are handling forward and back navigations for the same route here
21
- return [currentPath, nextPath].includes(path);
21
+ return {
22
+ // We are handling forward and back navigations for the same route here
23
+ isTransitioning: [currentPath, nextPath].includes(path),
24
+ types: viewTransition.types,
25
+ isForward: viewTransition.types.includes(constants.NAVIGATION_TYPE.FORWARD),
26
+ isBack: viewTransition.types.includes(constants.NAVIGATION_TYPE.BACK),
27
+ };
22
28
  }
23
- return false;
29
+ return { isTransitioning: false, isForward: false, isBack: false };
24
30
  };
25
31
 
26
32
  exports.useViewTransition = useViewTransition;
@@ -1,5 +1,8 @@
1
1
  class History {
2
+ listener;
3
+ tree;
2
4
  init(navigation) { }
5
+ unsubscribe() { }
3
6
  listen(listener) {
4
7
  this.listener = listener;
5
8
  }
@@ -1,4 +1,4 @@
1
- import type { Navigation, HistoryOptions, NavigationType } from '../types';
1
+ import type { Navigation, HistoryOptions, NavigationType, HistoryState } from '../types';
2
2
  import type { RouteTree } from '../tree/tree';
3
3
  export type Listener = (arg: {
4
4
  url: string;
@@ -6,13 +6,26 @@ export type Listener = (arg: {
6
6
  navigateState?: any;
7
7
  replace?: boolean;
8
8
  history?: boolean;
9
+ isBack?: boolean;
10
+ hasUAVisualTransition?: boolean;
11
+ viewTransition?: boolean;
12
+ viewTransitionTypes?: string[];
9
13
  }) => Promise<void>;
10
14
  export declare abstract class History {
11
15
  protected listener?: Listener;
12
16
  protected tree?: RouteTree;
13
17
  init(navigation: Navigation): void;
18
+ unsubscribe(): void;
14
19
  abstract save(navigation: Navigation): void;
15
20
  abstract go(to: number, options?: HistoryOptions): Promise<void>;
21
+ /**
22
+ * Получает стабильное значение window.history.state, необходимое для работы ViewTransition.
23
+ *
24
+ * Т.К. window.history.state обнуляется при инициализации tmsg чата.
25
+ *
26
+ * Возвращает undefined, если роут сразу вызывает redirect guard.
27
+ * */
28
+ abstract getCurrentState(): HistoryState | undefined;
16
29
  listen(listener: Listener): void;
17
30
  setTree(tree: RouteTree): void;
18
31
  }
@@ -1,5 +1,8 @@
1
1
  class History {
2
+ listener;
3
+ tree;
2
4
  init(navigation) { }
5
+ unsubscribe() { }
3
6
  listen(listener) {
4
7
  this.listener = listener;
5
8
  }
@@ -3,7 +3,10 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  class History {
6
+ listener;
7
+ tree;
6
8
  init(navigation) { }
9
+ unsubscribe() { }
7
10
  listen(listener) {
8
11
  this.listener = listener;
9
12
  }
@@ -50,9 +50,14 @@ const generateState = (navigation, currentState, index = 0) => {
50
50
  };
51
51
  };
52
52
  class ClientHistory extends History {
53
+ goPromiseResolve;
54
+ goPromiseReject;
55
+ currentIndex = 0;
56
+ currentState;
57
+ historyUnsubscribeCallback;
58
+ historyWrapper;
53
59
  constructor() {
54
60
  super();
55
- this.currentIndex = 0;
56
61
  this.historyWrapper = wrapHistory({
57
62
  onNavigate: ({ url, replace, navigateState }) => {
58
63
  this.listener({
@@ -63,16 +68,22 @@ class ClientHistory extends History {
63
68
  },
64
69
  });
65
70
  }
71
+ onNavigate;
72
+ getCurrentState() {
73
+ return this.currentState;
74
+ }
66
75
  init(navigation) {
67
76
  this.currentState = isHistoryState(window.history?.state)
68
77
  ? window.history.state
69
78
  : generateState(navigation);
70
79
  this.currentIndex = this.currentState.index;
71
80
  this.historyWrapper.init(this.currentState);
72
- this.historyWrapper.subscribe(async ({ path, state }) => {
81
+ this.historyUnsubscribeCallback = this.historyWrapper.subscribe(async ({ path, state, hasUAVisualTransition }) => {
73
82
  try {
74
83
  let navigationType;
75
84
  let navigateState;
85
+ const { viewTransition, viewTransitionTypes } = this.currentState;
86
+ const isBack = state.index < this.currentState.index;
76
87
  if (isHistoryState(state)) {
77
88
  const { key: prevKey, type: prevType } = this.currentState;
78
89
  const { key, type } = state;
@@ -95,6 +106,10 @@ class ClientHistory extends History {
95
106
  history: true,
96
107
  url: path,
97
108
  navigateState,
109
+ hasUAVisualTransition,
110
+ viewTransition,
111
+ viewTransitionTypes,
112
+ isBack,
98
113
  });
99
114
  this.goPromiseResolve?.();
100
115
  }
@@ -103,6 +118,9 @@ class ClientHistory extends History {
103
118
  }
104
119
  });
105
120
  }
121
+ unsubscribe() {
122
+ this.historyUnsubscribeCallback?.();
123
+ }
106
124
  save(navigation) {
107
125
  const { replace, url } = navigation;
108
126
  if (!replace) {
@@ -139,6 +157,8 @@ class ClientHistory extends History {
139
157
  this.goPromiseResolve = resolve;
140
158
  this.goPromiseReject = reject;
141
159
  });
160
+ this.currentState.viewTransition = options?.viewTransition;
161
+ this.currentState.viewTransitionTypes = options?.viewTransitionTypes;
142
162
  this.historyWrapper.history(to);
143
163
  return promise;
144
164
  }
@@ -1,24 +1,20 @@
1
1
  import { History } from './base';
2
- import type { Navigation, NavigationType, HistoryOptions } from '../types';
2
+ import type { Navigation, HistoryOptions, HistoryState } from '../types';
3
3
  import type { Wrapper } from './wrapper';
4
4
  import { wrapHistory } from './wrapper';
5
- interface HistoryState {
6
- key: string;
7
- type: NavigationType;
8
- navigateState?: any;
9
- index: number;
10
- }
11
5
  export declare class ClientHistory extends History {
12
6
  private goPromiseResolve;
13
7
  private goPromiseReject;
14
8
  private currentIndex;
15
9
  private currentState;
10
+ private historyUnsubscribeCallback;
16
11
  protected historyWrapper: Wrapper<HistoryState>;
17
12
  constructor();
18
13
  protected onNavigate: Parameters<typeof wrapHistory>[0]['onNavigate'];
14
+ getCurrentState(): HistoryState | undefined;
19
15
  init(navigation: Navigation): void;
16
+ unsubscribe(): void;
20
17
  save(navigation: Navigation): void;
21
18
  go(to: number, options?: HistoryOptions): Promise<void>;
22
19
  }
23
- export {};
24
20
  //# sourceMappingURL=client.d.ts.map
@@ -50,9 +50,14 @@ const generateState = (navigation, currentState, index = 0) => {
50
50
  };
51
51
  };
52
52
  class ClientHistory extends History {
53
+ goPromiseResolve;
54
+ goPromiseReject;
55
+ currentIndex = 0;
56
+ currentState;
57
+ historyUnsubscribeCallback;
58
+ historyWrapper;
53
59
  constructor() {
54
60
  super();
55
- this.currentIndex = 0;
56
61
  this.historyWrapper = wrapHistory({
57
62
  onNavigate: ({ url, replace, navigateState }) => {
58
63
  this.listener({
@@ -63,16 +68,22 @@ class ClientHistory extends History {
63
68
  },
64
69
  });
65
70
  }
71
+ onNavigate;
72
+ getCurrentState() {
73
+ return this.currentState;
74
+ }
66
75
  init(navigation) {
67
76
  this.currentState = isHistoryState(window.history?.state)
68
77
  ? window.history.state
69
78
  : generateState(navigation);
70
79
  this.currentIndex = this.currentState.index;
71
80
  this.historyWrapper.init(this.currentState);
72
- this.historyWrapper.subscribe(async ({ path, state }) => {
81
+ this.historyUnsubscribeCallback = this.historyWrapper.subscribe(async ({ path, state, hasUAVisualTransition }) => {
73
82
  try {
74
83
  let navigationType;
75
84
  let navigateState;
85
+ const { viewTransition, viewTransitionTypes } = this.currentState;
86
+ const isBack = state.index < this.currentState.index;
76
87
  if (isHistoryState(state)) {
77
88
  const { key: prevKey, type: prevType } = this.currentState;
78
89
  const { key, type } = state;
@@ -95,6 +106,10 @@ class ClientHistory extends History {
95
106
  history: true,
96
107
  url: path,
97
108
  navigateState,
109
+ hasUAVisualTransition,
110
+ viewTransition,
111
+ viewTransitionTypes,
112
+ isBack,
98
113
  });
99
114
  this.goPromiseResolve?.();
100
115
  }
@@ -103,6 +118,9 @@ class ClientHistory extends History {
103
118
  }
104
119
  });
105
120
  }
121
+ unsubscribe() {
122
+ this.historyUnsubscribeCallback?.();
123
+ }
106
124
  save(navigation) {
107
125
  const { replace, url } = navigation;
108
126
  if (!replace) {
@@ -139,6 +157,8 @@ class ClientHistory extends History {
139
157
  this.goPromiseResolve = resolve;
140
158
  this.goPromiseReject = reject;
141
159
  });
160
+ this.currentState.viewTransition = options?.viewTransition;
161
+ this.currentState.viewTransitionTypes = options?.viewTransitionTypes;
142
162
  this.historyWrapper.history(to);
143
163
  return promise;
144
164
  }
@@ -54,9 +54,14 @@ const generateState = (navigation, currentState, index = 0) => {
54
54
  };
55
55
  };
56
56
  class ClientHistory extends base.History {
57
+ goPromiseResolve;
58
+ goPromiseReject;
59
+ currentIndex = 0;
60
+ currentState;
61
+ historyUnsubscribeCallback;
62
+ historyWrapper;
57
63
  constructor() {
58
64
  super();
59
- this.currentIndex = 0;
60
65
  this.historyWrapper = wrapper.wrapHistory({
61
66
  onNavigate: ({ url, replace, navigateState }) => {
62
67
  this.listener({
@@ -67,16 +72,22 @@ class ClientHistory extends base.History {
67
72
  },
68
73
  });
69
74
  }
75
+ onNavigate;
76
+ getCurrentState() {
77
+ return this.currentState;
78
+ }
70
79
  init(navigation) {
71
80
  this.currentState = isHistoryState(window.history?.state)
72
81
  ? window.history.state
73
82
  : generateState(navigation);
74
83
  this.currentIndex = this.currentState.index;
75
84
  this.historyWrapper.init(this.currentState);
76
- this.historyWrapper.subscribe(async ({ path, state }) => {
85
+ this.historyUnsubscribeCallback = this.historyWrapper.subscribe(async ({ path, state, hasUAVisualTransition }) => {
77
86
  try {
78
87
  let navigationType;
79
88
  let navigateState;
89
+ const { viewTransition, viewTransitionTypes } = this.currentState;
90
+ const isBack = state.index < this.currentState.index;
80
91
  if (isHistoryState(state)) {
81
92
  const { key: prevKey, type: prevType } = this.currentState;
82
93
  const { key, type } = state;
@@ -99,6 +110,10 @@ class ClientHistory extends base.History {
99
110
  history: true,
100
111
  url: path,
101
112
  navigateState,
113
+ hasUAVisualTransition,
114
+ viewTransition,
115
+ viewTransitionTypes,
116
+ isBack,
102
117
  });
103
118
  this.goPromiseResolve?.();
104
119
  }
@@ -107,6 +122,9 @@ class ClientHistory extends base.History {
107
122
  }
108
123
  });
109
124
  }
125
+ unsubscribe() {
126
+ this.historyUnsubscribeCallback?.();
127
+ }
110
128
  save(navigation) {
111
129
  const { replace, url } = navigation;
112
130
  if (!replace) {
@@ -143,6 +161,8 @@ class ClientHistory extends base.History {
143
161
  this.goPromiseResolve = resolve;
144
162
  this.goPromiseReject = reject;
145
163
  });
164
+ this.currentState.viewTransition = options?.viewTransition;
165
+ this.currentState.viewTransitionTypes = options?.viewTransitionTypes;
146
166
  this.historyWrapper.history(to);
147
167
  return promise;
148
168
  }
@@ -2,5 +2,6 @@ import { History } from './base';
2
2
  export declare class ServerHistory extends History {
3
3
  save(): void;
4
4
  go(): Promise<void>;
5
+ getCurrentState(): any;
5
6
  }
6
7
  //# sourceMappingURL=server.d.ts.map
@@ -10,6 +10,13 @@ class ServerHistory extends History {
10
10
  });
11
11
  return Promise.resolve();
12
12
  }
13
+ getCurrentState() {
14
+ logger.warn({
15
+ event: 'history.server',
16
+ message: 'Trying to get current state on server',
17
+ });
18
+ return null;
19
+ }
13
20
  }
14
21
 
15
22
  export { ServerHistory };
@@ -14,6 +14,13 @@ class ServerHistory extends base.History {
14
14
  });
15
15
  return Promise.resolve();
16
16
  }
17
+ getCurrentState() {
18
+ logger.logger.warn({
19
+ event: 'history.server',
20
+ message: 'Trying to get current state on server',
21
+ });
22
+ return null;
23
+ }
17
24
  }
18
25
 
19
26
  exports.ServerHistory = ServerHistory;
@@ -14,7 +14,7 @@ const wrapHistory = ({ onNavigate }) => {
14
14
  throw new Error('Method not implemented');
15
15
  },
16
16
  init: noop,
17
- subscribe: noop,
17
+ subscribe: () => noop,
18
18
  };
19
19
  }
20
20
  let browserHistory = window.history;
@@ -59,12 +59,17 @@ const wrapHistory = ({ onNavigate }) => {
59
59
  replaceState(state, '');
60
60
  },
61
61
  subscribe: (handler) => {
62
- window.addEventListener('popstate', ({ state }) => {
62
+ const listener = ({ state, hasUAVisualTransition }) => {
63
63
  handler({
64
64
  path: window.location.pathname + window.location.search + window.location.hash,
65
65
  state,
66
+ hasUAVisualTransition,
66
67
  });
67
- });
68
+ };
69
+ window.addEventListener('popstate', listener);
70
+ return () => {
71
+ window.removeEventListener('popstate', listener);
72
+ };
68
73
  },
69
74
  };
70
75
  };
@@ -9,7 +9,8 @@ export interface Wrapper<T> {
9
9
  subscribe(handler: (arg: {
10
10
  path: string;
11
11
  state: T;
12
- }) => void): void;
12
+ hasUAVisualTransition?: boolean;
13
+ }) => void): () => void;
13
14
  }
14
15
  interface NavigateHandler {
15
16
  (arg: {
@@ -14,7 +14,7 @@ const wrapHistory = ({ onNavigate }) => {
14
14
  throw new Error('Method not implemented');
15
15
  },
16
16
  init: noop,
17
- subscribe: noop,
17
+ subscribe: () => noop,
18
18
  };
19
19
  }
20
20
  let browserHistory = window.history;
@@ -59,12 +59,17 @@ const wrapHistory = ({ onNavigate }) => {
59
59
  replaceState(state, '');
60
60
  },
61
61
  subscribe: (handler) => {
62
- window.addEventListener('popstate', ({ state }) => {
62
+ const listener = ({ state, hasUAVisualTransition }) => {
63
63
  handler({
64
64
  path: window.location.pathname + window.location.search + window.location.hash,
65
65
  state,
66
+ hasUAVisualTransition,
66
67
  });
67
- });
68
+ };
69
+ window.addEventListener('popstate', listener);
70
+ return () => {
71
+ window.removeEventListener('popstate', listener);
72
+ };
68
73
  },
69
74
  };
70
75
  };
@@ -22,7 +22,7 @@ const wrapHistory = ({ onNavigate }) => {
22
22
  throw new Error('Method not implemented');
23
23
  },
24
24
  init: noop__default["default"],
25
- subscribe: noop__default["default"],
25
+ subscribe: () => noop__default["default"],
26
26
  };
27
27
  }
28
28
  let browserHistory = window.history;
@@ -67,12 +67,17 @@ const wrapHistory = ({ onNavigate }) => {
67
67
  replaceState(state, '');
68
68
  },
69
69
  subscribe: (handler) => {
70
- window.addEventListener('popstate', ({ state }) => {
70
+ const listener = ({ state, hasUAVisualTransition }) => {
71
71
  handler({
72
72
  path: window.location.pathname + window.location.search + window.location.hash,
73
73
  state,
74
+ hasUAVisualTransition,
74
75
  });
75
- });
76
+ };
77
+ window.addEventListener('popstate', listener);
78
+ return () => {
79
+ window.removeEventListener('popstate', listener);
80
+ };
76
81
  },
77
82
  };
78
83
  };