@tramvai/module-router 2.67.0 → 2.70.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.
Files changed (2) hide show
  1. package/lib/index.browser.js +17 -29
  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, 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, ENV_MANAGER_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,8 +599,13 @@ const providers = [
599
599
  provide({
600
600
  provide: commandLineListTokens.customerStart,
601
601
  multi: true,
602
- useFactory: ({ router, store }) => {
602
+ useFactory: ({ router, store, envManager }) => {
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
+ }
604
609
  const currentRoute = store.getState(RouterStore).currentRoute;
605
610
  return router.rehydrate({
606
611
  to: currentRoute,
@@ -610,6 +615,7 @@ const providers = [
610
615
  deps: {
611
616
  router: ROUTER_TOKEN,
612
617
  store: STORE_TOKEN,
618
+ envManager: ENV_MANAGER_TOKEN,
613
619
  },
614
620
  }),
615
621
  provide({
@@ -617,8 +623,12 @@ const providers = [
617
623
  // после этого уже можно будет делать переходы и т.д.
618
624
  provide: commandLineListTokens.clear,
619
625
  multi: true,
620
- useFactory: ({ router, store }) => {
626
+ useFactory: ({ router, store, envManager }) => {
621
627
  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
+ }
622
632
  const routerState = store.getState().router;
623
633
  if (routerState.currentUrl.href !== window.location.href) {
624
634
  store.dispatch(setUrlOnRehydrate(router.getCurrentUrl()));
@@ -629,6 +639,7 @@ const providers = [
629
639
  deps: {
630
640
  router: ROUTER_TOKEN,
631
641
  store: STORE_TOKEN,
642
+ envManager: ENV_MANAGER_TOKEN,
632
643
  },
633
644
  }),
634
645
  provide({
@@ -637,10 +648,8 @@ const providers = [
637
648
  provide: commandLineListTokens.clear,
638
649
  multi: true,
639
650
  useFactory: (deps) => {
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))) {
651
+ // actions already executed for CSR fallback before this stage
652
+ if (deps.envManager.get('TRAMVAI_FORCE_CLIENT_SIDE_RENDERING') === 'true') {
644
653
  return noop;
645
654
  }
646
655
  return runActionsFactory(deps);
@@ -651,28 +660,7 @@ const providers = [
651
660
  actionRegistry: ACTION_REGISTRY_TOKEN,
652
661
  actionPageRunner: ACTION_PAGE_RUNNER_TOKEN,
653
662
  renderMode: TRAMVAI_RENDER_MODE,
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,
663
+ envManager: ENV_MANAGER_TOKEN,
676
664
  },
677
665
  }),
678
666
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-router",
3
- "version": "2.67.0",
3
+ "version": "2.70.0",
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.67.0",
33
- "@tramvai/tokens-child-app": "2.67.0",
34
- "@tramvai/tokens-render": "2.67.0",
35
- "@tramvai/tokens-router": "2.67.0",
36
- "@tramvai/tokens-server": "2.67.0",
37
- "@tramvai/experiments": "2.67.0"
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"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "@tinkoff/utils": "^2.1.2",
41
- "@tramvai/cli": "2.67.0",
42
- "@tramvai/core": "2.67.0",
43
- "@tramvai/module-log": "2.67.0",
44
- "@tramvai/module-server": "2.67.0",
45
- "@tramvai/papi": "2.67.0",
46
- "@tramvai/state": "2.67.0",
47
- "@tramvai/test-helpers": "2.67.0",
48
- "@tramvai/test-mocks": "2.67.0",
49
- "@tramvai/tokens-common": "2.67.0",
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",
50
50
  "@tinkoff/dippy": "0.8.12",
51
51
  "react": "*",
52
52
  "tslib": "^2.4.0"