@tramvai/module-router 2.70.0 → 2.70.1

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 (2) hide show
  1. package/lib/index.browser.js +29 -17
  2. package/package.json +16 -16
@@ -2,7 +2,7 @@ import { provide, commandLineListTokens, createToken as createToken$1, Module, D
2
2
  import { Provider, setLogger, NoSpaRouter, Router, useNavigate, useRoute } from '@tinkoff/router';
3
3
  export { Provider, useNavigate, useRoute, useRouter, useUrl } from '@tinkoff/router';
4
4
  import noop from '@tinkoff/utils/function/noop';
5
- import { LOGGER_TOKEN, BUNDLE_MANAGER_TOKEN, ACTION_REGISTRY_TOKEN, RESPONSE_MANAGER_TOKEN, DISPATCHER_TOKEN, DISPATCHER_CONTEXT_TOKEN, CONTEXT_TOKEN, COMPONENT_REGISTRY_TOKEN, COMBINE_REDUCERS, STORE_TOKEN, ENV_MANAGER_TOKEN, ACTION_PAGE_RUNNER_TOKEN } from '@tramvai/tokens-common';
5
+ import { LOGGER_TOKEN, BUNDLE_MANAGER_TOKEN, ACTION_REGISTRY_TOKEN, RESPONSE_MANAGER_TOKEN, DISPATCHER_TOKEN, DISPATCHER_CONTEXT_TOKEN, CONTEXT_TOKEN, COMPONENT_REGISTRY_TOKEN, COMBINE_REDUCERS, STORE_TOKEN, ACTION_PAGE_RUNNER_TOKEN } from '@tramvai/tokens-common';
6
6
  import { ROUTER_GUARD_TOKEN, PAGE_SERVICE_TOKEN, ROUTE_TRANSFORM_TOKEN, ROUTER_TOKEN, ROUTES_TOKEN, ROUTE_RESOLVE_TOKEN, ROUTER_SPA_ACTIONS_RUN_MODE_TOKEN, LINK_PREFETCH_MANAGER_TOKEN } from '@tramvai/tokens-router';
7
7
  export * from '@tramvai/tokens-router';
8
8
  import { EXTEND_RENDER, TRAMVAI_RENDER_MODE } from '@tramvai/tokens-render';
@@ -599,13 +599,8 @@ const providers = [
599
599
  provide({
600
600
  provide: commandLineListTokens.customerStart,
601
601
  multi: true,
602
- useFactory: ({ router, store, envManager }) => {
602
+ useFactory: ({ router, store }) => {
603
603
  return async function routerInit() {
604
- // run full navigation flow for CSR fallback on application start
605
- if (envManager.get('TRAMVAI_FORCE_CLIENT_SIDE_RENDERING') === 'true') {
606
- router.start();
607
- return router.navigate({ url: window.location.href, replace: true });
608
- }
609
604
  const currentRoute = store.getState(RouterStore).currentRoute;
610
605
  return router.rehydrate({
611
606
  to: currentRoute,
@@ -615,7 +610,6 @@ const providers = [
615
610
  deps: {
616
611
  router: ROUTER_TOKEN,
617
612
  store: STORE_TOKEN,
618
- envManager: ENV_MANAGER_TOKEN,
619
613
  },
620
614
  }),
621
615
  provide({
@@ -623,12 +617,8 @@ const providers = [
623
617
  // после этого уже можно будет делать переходы и т.д.
624
618
  provide: commandLineListTokens.clear,
625
619
  multi: true,
626
- useFactory: ({ router, store, envManager }) => {
620
+ useFactory: ({ router, store }) => {
627
621
  return function routerStart() {
628
- // router already started for CSR fallback on this stage
629
- if (envManager.get('TRAMVAI_FORCE_CLIENT_SIDE_RENDERING') === 'true') {
630
- return;
631
- }
632
622
  const routerState = store.getState().router;
633
623
  if (routerState.currentUrl.href !== window.location.href) {
634
624
  store.dispatch(setUrlOnRehydrate(router.getCurrentUrl()));
@@ -639,7 +629,6 @@ const providers = [
639
629
  deps: {
640
630
  router: ROUTER_TOKEN,
641
631
  store: STORE_TOKEN,
642
- envManager: ENV_MANAGER_TOKEN,
643
632
  },
644
633
  }),
645
634
  provide({
@@ -648,8 +637,10 @@ const providers = [
648
637
  provide: commandLineListTokens.clear,
649
638
  multi: true,
650
639
  useFactory: (deps) => {
651
- // actions already executed for CSR fallback before this stage
652
- if (deps.envManager.get('TRAMVAI_FORCE_CLIENT_SIDE_RENDERING') === 'true') {
640
+ const currentRoute = deps.store.getState(RouterStore).currentRoute;
641
+ // in client-side rendering mode, action will be executed on first navigation
642
+ if (deps.renderMode === 'client' &&
643
+ (!currentRoute || (currentRoute && currentRoute.actualPath !== window.location.pathname))) {
653
644
  return noop;
654
645
  }
655
646
  return runActionsFactory(deps);
@@ -660,7 +651,28 @@ const providers = [
660
651
  actionRegistry: ACTION_REGISTRY_TOKEN,
661
652
  actionPageRunner: ACTION_PAGE_RUNNER_TOKEN,
662
653
  renderMode: TRAMVAI_RENDER_MODE,
663
- envManager: ENV_MANAGER_TOKEN,
654
+ },
655
+ }),
656
+ provide({
657
+ provide: commandLineListTokens.clear,
658
+ multi: true,
659
+ useFactory: ({ store, router, renderMode }) => {
660
+ return async function csrFirstNavigation() {
661
+ const currentRoute = store.getState(RouterStore).currentRoute;
662
+ // in client-side rendering mode, if current route inconsistent with current location,
663
+ // run navigation to current location.
664
+ if (renderMode === 'client' &&
665
+ (!currentRoute || (currentRoute && currentRoute.actualPath !== window.location.pathname))) {
666
+ // replace because otherwice we will push in the history the same url twice,
667
+ // and history.back will return to the same url
668
+ return router.navigate({ url: window.location.href, replace: true });
669
+ }
670
+ };
671
+ },
672
+ deps: {
673
+ store: STORE_TOKEN,
674
+ router: ROUTER_TOKEN,
675
+ renderMode: TRAMVAI_RENDER_MODE,
664
676
  },
665
677
  }),
666
678
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-router",
3
- "version": "2.70.0",
3
+ "version": "2.70.1",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "browser": {
@@ -29,24 +29,24 @@
29
29
  "@tinkoff/errors": "0.3.5",
30
30
  "@tinkoff/router": "0.2.7",
31
31
  "@tinkoff/url": "0.8.4",
32
- "@tramvai/react": "2.70.0",
33
- "@tramvai/tokens-child-app": "2.70.0",
34
- "@tramvai/tokens-render": "2.70.0",
35
- "@tramvai/tokens-router": "2.70.0",
36
- "@tramvai/tokens-server": "2.70.0",
37
- "@tramvai/experiments": "2.70.0"
32
+ "@tramvai/react": "2.70.1",
33
+ "@tramvai/tokens-child-app": "2.70.1",
34
+ "@tramvai/tokens-render": "2.70.1",
35
+ "@tramvai/tokens-router": "2.70.1",
36
+ "@tramvai/tokens-server": "2.70.1",
37
+ "@tramvai/experiments": "2.70.1"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "@tinkoff/utils": "^2.1.2",
41
- "@tramvai/cli": "2.70.0",
42
- "@tramvai/core": "2.70.0",
43
- "@tramvai/module-log": "2.70.0",
44
- "@tramvai/module-server": "2.70.0",
45
- "@tramvai/papi": "2.70.0",
46
- "@tramvai/state": "2.70.0",
47
- "@tramvai/test-helpers": "2.70.0",
48
- "@tramvai/test-mocks": "2.70.0",
49
- "@tramvai/tokens-common": "2.70.0",
41
+ "@tramvai/cli": "2.70.1",
42
+ "@tramvai/core": "2.70.1",
43
+ "@tramvai/module-log": "2.70.1",
44
+ "@tramvai/module-server": "2.70.1",
45
+ "@tramvai/papi": "2.70.1",
46
+ "@tramvai/state": "2.70.1",
47
+ "@tramvai/test-helpers": "2.70.1",
48
+ "@tramvai/test-mocks": "2.70.1",
49
+ "@tramvai/tokens-common": "2.70.1",
50
50
  "@tinkoff/dippy": "0.8.12",
51
51
  "react": "*",
52
52
  "tslib": "^2.4.0"