@tramvai/module-router 1.76.1 → 1.76.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.
Files changed (2) hide show
  1. package/lib/index.browser.js +26 -11
  2. package/package.json +14 -14
@@ -1,6 +1,7 @@
1
1
  import { provide, commandLineListTokens, Module, DI_TOKEN, COMMAND_LINE_RUNNER_TOKEN } from '@tramvai/core';
2
2
  import { Provider, setLogger, NoSpaRouter, Router } from '@tinkoff/router';
3
3
  export { Link, Provider, useNavigate, useRoute, useRouter, useUrl } from '@tinkoff/router';
4
+ import noop from '@tinkoff/utils/function/noop';
4
5
  import { LOGGER_TOKEN, BUNDLE_MANAGER_TOKEN, ACTION_REGISTRY_TOKEN, RESPONSE_MANAGER_TOKEN, CONTEXT_TOKEN, COMPONENT_REGISTRY_TOKEN, COMBINE_REDUCERS, STORE_TOKEN, ACTION_PAGE_RUNNER_TOKEN } from '@tramvai/tokens-common';
5
6
  import { ROUTER_GUARD_TOKEN, ROUTE_TRANSFORM_TOKEN, ROUTER_TOKEN, ROUTES_TOKEN, ROUTE_RESOLVE_TOKEN, ROUTER_SPA_ACTIONS_RUN_MODE_TOKEN, PAGE_SERVICE_TOKEN } from '@tramvai/tokens-router';
6
7
  export * from '@tramvai/tokens-router';
@@ -15,7 +16,6 @@ import React from 'react';
15
16
  import { isFileSystemPageComponent, fileSystemPagesEnabled, getStaticFileSystemPages, fileSystemPageToRoute } from '@tramvai/experiments';
16
17
  import uniq from '@tinkoff/utils/array/uniq';
17
18
  import { isRedirectFoundError, isNotFoundError } from '@tinkoff/errors';
18
- import noop from '@tinkoff/utils/function/noop';
19
19
  import { __decorate } from 'tslib';
20
20
 
21
21
  const setCurrentNavigation = createEvent('SET_CURRENT_ROUTE');
@@ -451,15 +451,9 @@ const providers = [
451
451
  provide({
452
452
  provide: commandLineListTokens.customerStart,
453
453
  multi: true,
454
- useFactory: ({ router, store, renderMode }) => {
454
+ useFactory: ({ router, store }) => {
455
455
  return async function routerInit() {
456
456
  const currentRoute = store.getState(RouterStore).currentRoute;
457
- // in client-side rendering mode, run navigation before hydration,
458
- // because currentRoute from initialState can be undefined or incorrect
459
- if (renderMode === 'client' &&
460
- (!currentRoute || (currentRoute && currentRoute.actualPath !== window.location.pathname))) {
461
- await router.navigate(window.location.href);
462
- }
463
457
  return router.rehydrate({
464
458
  to: currentRoute,
465
459
  });
@@ -468,7 +462,6 @@ const providers = [
468
462
  deps: {
469
463
  router: ROUTER_TOKEN,
470
464
  store: STORE_TOKEN,
471
- renderMode: TRAMVAI_RENDER_MODE,
472
465
  },
473
466
  }),
474
467
  provide({
@@ -497,10 +490,10 @@ const providers = [
497
490
  multi: true,
498
491
  useFactory: (deps) => {
499
492
  const currentRoute = deps.store.getState(RouterStore).currentRoute;
500
- // in client-side rendering mode, action already was executed
493
+ // in client-side rendering mode, action will be executed on first navigation
501
494
  if (deps.renderMode === 'client' &&
502
495
  (!currentRoute || (currentRoute && currentRoute.actualPath !== window.location.pathname))) {
503
- return;
496
+ return noop;
504
497
  }
505
498
  return runActionsFactory(deps);
506
499
  },
@@ -512,6 +505,28 @@ const providers = [
512
505
  renderMode: TRAMVAI_RENDER_MODE,
513
506
  },
514
507
  }),
508
+ provide({
509
+ provide: commandLineListTokens.clear,
510
+ multi: true,
511
+ useFactory: (deps) => {
512
+ return async function csrFirstNavigation() {
513
+ const currentRoute = deps.store.getState(RouterStore).currentRoute;
514
+ // in client-side rendering mode, if current route inconsistent with current location,
515
+ // run navigation to current location.
516
+ if (deps.renderMode === 'client' &&
517
+ (!currentRoute || (currentRoute && currentRoute.actualPath !== window.location.pathname))) {
518
+ return deps.router.navigate(window.location.href);
519
+ }
520
+ };
521
+ },
522
+ deps: {
523
+ store: STORE_TOKEN,
524
+ router: ROUTER_TOKEN,
525
+ actionRegistry: ACTION_REGISTRY_TOKEN,
526
+ actionPageRunner: ACTION_PAGE_RUNNER_TOKEN,
527
+ renderMode: TRAMVAI_RENDER_MODE,
528
+ },
529
+ }),
515
530
  ];
516
531
 
517
532
  const generateForRoot = (mainModule) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-router",
3
- "version": "1.76.1",
3
+ "version": "1.76.2",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "browser": {
@@ -25,22 +25,22 @@
25
25
  "@tinkoff/errors": "0.2.18",
26
26
  "@tinkoff/router": "0.1.70",
27
27
  "@tinkoff/url": "0.7.37",
28
- "@tramvai/tokens-render": "1.76.1",
29
- "@tramvai/tokens-router": "1.76.1",
30
- "@tramvai/tokens-server": "1.76.1",
31
- "@tramvai/experiments": "1.76.1"
28
+ "@tramvai/tokens-render": "1.76.2",
29
+ "@tramvai/tokens-router": "1.76.2",
30
+ "@tramvai/tokens-server": "1.76.2",
31
+ "@tramvai/experiments": "1.76.2"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "@tinkoff/utils": "^2.1.2",
35
- "@tramvai/cli": "1.76.1",
36
- "@tramvai/core": "1.76.1",
37
- "@tramvai/module-log": "1.76.1",
38
- "@tramvai/module-server": "1.76.1",
39
- "@tramvai/papi": "1.76.1",
40
- "@tramvai/state": "1.76.1",
41
- "@tramvai/test-helpers": "1.76.1",
42
- "@tramvai/test-mocks": "1.76.1",
43
- "@tramvai/tokens-common": "1.76.1",
35
+ "@tramvai/cli": "1.76.2",
36
+ "@tramvai/core": "1.76.2",
37
+ "@tramvai/module-log": "1.76.2",
38
+ "@tramvai/module-server": "1.76.2",
39
+ "@tramvai/papi": "1.76.2",
40
+ "@tramvai/state": "1.76.2",
41
+ "@tramvai/test-helpers": "1.76.2",
42
+ "@tramvai/test-mocks": "1.76.2",
43
+ "@tramvai/tokens-common": "1.76.2",
44
44
  "@tinkoff/dippy": "0.7.38",
45
45
  "react": "*",
46
46
  "tslib": "^2.0.3"