@tarojs/router 3.6.30 → 3.6.31-canary.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.
package/dist/api.js CHANGED
@@ -54,6 +54,7 @@ function navigate(option, method) {
54
54
  const pathPieces = processNavigateUrl(option);
55
55
  const state = { timestamp: Date.now() };
56
56
  if (method === 'navigateTo') {
57
+ // Note: 由于 spa 会针对弱网情况下,短时间内多次跳转同一个页面跳转加了锁,后续如果有用户反馈返回无效,那可能是这个问题
57
58
  history.push(pathPieces, state);
58
59
  }
59
60
  else if (method === 'redirectTo' || method === 'switchTab') {
package/dist/index.cjs.js CHANGED
@@ -15,7 +15,8 @@ var UniversalRouter = require('universal-router');
15
15
  function loadAnimateStyle(ms = 300) {
16
16
  const css = `
17
17
  body {
18
- overflow: hidden; // 防止 iOS 页面滚动
18
+ /* 防止 iOS 页面滚动 */
19
+ overflow: hidden;
19
20
  }
20
21
  .taro_router > .taro_page {
21
22
  position: absolute;
@@ -142,7 +143,7 @@ function loadNavigationBarStyle() {
142
143
  to {
143
144
  transform: rotate(360deg);
144
145
  }
145
- }
146
+ }
146
147
 
147
148
  .taro-navigation-bar-no-icon > .taro-navigation-bar-home {
148
149
  display: none;
@@ -573,6 +574,7 @@ function navigate(option, method) {
573
574
  const pathPieces = processNavigateUrl(option);
574
575
  const state = { timestamp: Date.now() };
575
576
  if (method === 'navigateTo') {
577
+ // Note: 由于 spa 会针对弱网情况下,短时间内多次跳转同一个页面跳转加了锁,后续如果有用户反馈返回无效,那可能是这个问题
576
578
  exports.history.push(pathPieces, state);
577
579
  }
578
580
  else if (method === 'redirectTo' || method === 'switchTab') {
@@ -1478,6 +1480,10 @@ function createRouter(history$1, app, config, framework) {
1478
1480
  }
1479
1481
  RouterConfig.config = config;
1480
1482
  const handler = new PageHandler(config, history$1);
1483
+ // Note: 弱网情况下,快速切换 tab,会造成同个页面实例被多次挂在到页面上,原因是资源请求是异步的,短时间内发起多个请求,
1484
+ // 会在资源加载完成后,同时走到挂载的逻辑,造成 pageStampId 更新不及时,两个 page 的Id 相同,后面很多操作是通过 getElementById 来进行的
1485
+ // 所以需要加一个锁来应对这个情况
1486
+ const pageLock = {};
1481
1487
  routesAlias.set(handler.router.customRoutes);
1482
1488
  const basename = handler.router.basename;
1483
1489
  const routes = handler.routes.map(route => {
@@ -1501,24 +1507,30 @@ function createRouter(history$1, app, config, framework) {
1501
1507
  app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
1502
1508
  const render = ({ location, action }) => tslib.__awaiter(this, void 0, void 0, function* () {
1503
1509
  var _c, _d, _e, _f, _g, _h, _j, _k;
1504
- handler.pathname = decodeURI(location.pathname);
1510
+ // Note: 由于下面有异步加载操作 先不要在这里去设置 handler.pathname
1511
+ const currentPathname = decodeURI(location.pathname);
1505
1512
  if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
1506
1513
  window.scrollTo(0, 0);
1507
1514
  runtime.eventCenter.trigger('__taroRouterChange', {
1508
1515
  toLocation: {
1509
- path: handler.pathname
1516
+ path: currentPathname
1510
1517
  }
1511
1518
  });
1512
- let element, params;
1519
+ let element, context, params;
1520
+ const routerPath = handler.router.forcePath || currentPathname;
1521
+ pageLock[routerPath] = typeof pageLock[routerPath] === 'number' ? pageLock[routerPath] + 1 : 1;
1522
+ const currentLock = pageLock[routerPath];
1523
+ let postLock;
1513
1524
  try {
1514
- const result = yield router.resolve(handler.router.forcePath || handler.pathname);
1515
- [element, , params] = yield Promise.all(result);
1525
+ const result = yield router.resolve(routerPath);
1526
+ [element, context, params] = yield Promise.all(result);
1527
+ postLock = pageLock[routerPath];
1516
1528
  }
1517
1529
  catch (error) {
1518
1530
  if (error.status === 404) {
1519
1531
  const notFoundEvent = {
1520
1532
  isEntryPage: stacks.length === 0,
1521
- path: handler.pathname,
1533
+ path: currentPathname,
1522
1534
  query: handler.getQuery(createStampId()),
1523
1535
  };
1524
1536
  (_d = app.onPageNotFound) === null || _d === void 0 ? void 0 : _d.call(app, notFoundEvent);
@@ -1532,9 +1544,12 @@ function createRouter(history$1, app, config, framework) {
1532
1544
  throw error;
1533
1545
  }
1534
1546
  }
1535
- if (!element)
1547
+ if (!element || currentLock !== postLock)
1536
1548
  return;
1537
- const pageConfig = handler.pageConfig;
1549
+ // Note: 异步结束后,在设置 handler.pathname
1550
+ // context.pathname 在 universal-router 被处理过了,是发起资源请求的时候传入的 pathname,即 await router.resolve(routerPath) 这个 routerPath
1551
+ handler.pathname = context.pathname;
1552
+ const { pathname, pageConfig } = handler;
1538
1553
  let enablePullDownRefresh = ((_e = config === null || config === void 0 ? void 0 : config.window) === null || _e === void 0 ? void 0 : _e.enablePullDownRefresh) || false;
1539
1554
  let navigationStyle = ((_f = config === null || config === void 0 ? void 0 : config.window) === null || _f === void 0 ? void 0 : _f.navigationStyle) || 'default';
1540
1555
  let navigationBarTextStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationBarTextStyle) || 'white';
@@ -1555,7 +1570,6 @@ function createRouter(history$1, app, config, framework) {
1555
1570
  }
1556
1571
  runtime.eventCenter.trigger('__taroSetNavigationStyle', navigationStyle, navigationBarTextStyle, navigationBarBackgroundColor);
1557
1572
  const currentPage = runtime.Current.page;
1558
- const pathname = handler.pathname;
1559
1573
  const methodName = (_j = stacks.method) !== null && _j !== void 0 ? _j : '';
1560
1574
  const cacheTabs = stacks.getTabs();
1561
1575
  let shouldLoad = false;
@@ -1571,7 +1585,7 @@ function createRouter(history$1, app, config, framework) {
1571
1585
  }
1572
1586
  shouldLoad = true;
1573
1587
  }
1574
- else if (currentPage && handler.isTabBar(handler.pathname)) {
1588
+ else if (currentPage && handler.isTabBar(pathname)) {
1575
1589
  if (handler.isSamePage(currentPage))
1576
1590
  return;
1577
1591
  if (handler.isTabBar(currentPage.path)) {
@@ -1589,8 +1603,8 @@ function createRouter(history$1, app, config, framework) {
1589
1603
  handler.unload(currentPage, stacks.length, true);
1590
1604
  }
1591
1605
  }
1592
- if (cacheTabs[handler.pathname]) {
1593
- stacks.popTab(handler.pathname);
1606
+ if (cacheTabs[pathname]) {
1607
+ stacks.popTab(pathname);
1594
1608
  return handler.show(stacks.getItem(0), pageConfig, 0);
1595
1609
  }
1596
1610
  shouldLoad = true;
package/dist/index.esm.js CHANGED
@@ -14,7 +14,8 @@ import UniversalRouter from 'universal-router';
14
14
  function loadAnimateStyle(ms = 300) {
15
15
  const css = `
16
16
  body {
17
- overflow: hidden; // 防止 iOS 页面滚动
17
+ /* 防止 iOS 页面滚动 */
18
+ overflow: hidden;
18
19
  }
19
20
  .taro_router > .taro_page {
20
21
  position: absolute;
@@ -141,7 +142,7 @@ function loadNavigationBarStyle() {
141
142
  to {
142
143
  transform: rotate(360deg);
143
144
  }
144
- }
145
+ }
145
146
 
146
147
  .taro-navigation-bar-no-icon > .taro-navigation-bar-home {
147
148
  display: none;
@@ -572,6 +573,7 @@ function navigate(option, method) {
572
573
  const pathPieces = processNavigateUrl(option);
573
574
  const state = { timestamp: Date.now() };
574
575
  if (method === 'navigateTo') {
576
+ // Note: 由于 spa 会针对弱网情况下,短时间内多次跳转同一个页面跳转加了锁,后续如果有用户反馈返回无效,那可能是这个问题
575
577
  history.push(pathPieces, state);
576
578
  }
577
579
  else if (method === 'redirectTo' || method === 'switchTab') {
@@ -1477,6 +1479,10 @@ function createRouter(history, app, config, framework) {
1477
1479
  }
1478
1480
  RouterConfig.config = config;
1479
1481
  const handler = new PageHandler(config, history);
1482
+ // Note: 弱网情况下,快速切换 tab,会造成同个页面实例被多次挂在到页面上,原因是资源请求是异步的,短时间内发起多个请求,
1483
+ // 会在资源加载完成后,同时走到挂载的逻辑,造成 pageStampId 更新不及时,两个 page 的Id 相同,后面很多操作是通过 getElementById 来进行的
1484
+ // 所以需要加一个锁来应对这个情况
1485
+ const pageLock = {};
1480
1486
  routesAlias.set(handler.router.customRoutes);
1481
1487
  const basename = handler.router.basename;
1482
1488
  const routes = handler.routes.map(route => {
@@ -1500,24 +1506,30 @@ function createRouter(history, app, config, framework) {
1500
1506
  app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
1501
1507
  const render = ({ location, action }) => __awaiter(this, void 0, void 0, function* () {
1502
1508
  var _c, _d, _e, _f, _g, _h, _j, _k;
1503
- handler.pathname = decodeURI(location.pathname);
1509
+ // Note: 由于下面有异步加载操作 先不要在这里去设置 handler.pathname
1510
+ const currentPathname = decodeURI(location.pathname);
1504
1511
  if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
1505
1512
  window.scrollTo(0, 0);
1506
1513
  eventCenter.trigger('__taroRouterChange', {
1507
1514
  toLocation: {
1508
- path: handler.pathname
1515
+ path: currentPathname
1509
1516
  }
1510
1517
  });
1511
- let element, params;
1518
+ let element, context, params;
1519
+ const routerPath = handler.router.forcePath || currentPathname;
1520
+ pageLock[routerPath] = typeof pageLock[routerPath] === 'number' ? pageLock[routerPath] + 1 : 1;
1521
+ const currentLock = pageLock[routerPath];
1522
+ let postLock;
1512
1523
  try {
1513
- const result = yield router.resolve(handler.router.forcePath || handler.pathname);
1514
- [element, , params] = yield Promise.all(result);
1524
+ const result = yield router.resolve(routerPath);
1525
+ [element, context, params] = yield Promise.all(result);
1526
+ postLock = pageLock[routerPath];
1515
1527
  }
1516
1528
  catch (error) {
1517
1529
  if (error.status === 404) {
1518
1530
  const notFoundEvent = {
1519
1531
  isEntryPage: stacks.length === 0,
1520
- path: handler.pathname,
1532
+ path: currentPathname,
1521
1533
  query: handler.getQuery(createStampId()),
1522
1534
  };
1523
1535
  (_d = app.onPageNotFound) === null || _d === void 0 ? void 0 : _d.call(app, notFoundEvent);
@@ -1531,9 +1543,12 @@ function createRouter(history, app, config, framework) {
1531
1543
  throw error;
1532
1544
  }
1533
1545
  }
1534
- if (!element)
1546
+ if (!element || currentLock !== postLock)
1535
1547
  return;
1536
- const pageConfig = handler.pageConfig;
1548
+ // Note: 异步结束后,在设置 handler.pathname
1549
+ // context.pathname 在 universal-router 被处理过了,是发起资源请求的时候传入的 pathname,即 await router.resolve(routerPath) 这个 routerPath
1550
+ handler.pathname = context.pathname;
1551
+ const { pathname, pageConfig } = handler;
1537
1552
  let enablePullDownRefresh = ((_e = config === null || config === void 0 ? void 0 : config.window) === null || _e === void 0 ? void 0 : _e.enablePullDownRefresh) || false;
1538
1553
  let navigationStyle = ((_f = config === null || config === void 0 ? void 0 : config.window) === null || _f === void 0 ? void 0 : _f.navigationStyle) || 'default';
1539
1554
  let navigationBarTextStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationBarTextStyle) || 'white';
@@ -1554,7 +1569,6 @@ function createRouter(history, app, config, framework) {
1554
1569
  }
1555
1570
  eventCenter.trigger('__taroSetNavigationStyle', navigationStyle, navigationBarTextStyle, navigationBarBackgroundColor);
1556
1571
  const currentPage = Current.page;
1557
- const pathname = handler.pathname;
1558
1572
  const methodName = (_j = stacks.method) !== null && _j !== void 0 ? _j : '';
1559
1573
  const cacheTabs = stacks.getTabs();
1560
1574
  let shouldLoad = false;
@@ -1570,7 +1584,7 @@ function createRouter(history, app, config, framework) {
1570
1584
  }
1571
1585
  shouldLoad = true;
1572
1586
  }
1573
- else if (currentPage && handler.isTabBar(handler.pathname)) {
1587
+ else if (currentPage && handler.isTabBar(pathname)) {
1574
1588
  if (handler.isSamePage(currentPage))
1575
1589
  return;
1576
1590
  if (handler.isTabBar(currentPage.path)) {
@@ -1588,8 +1602,8 @@ function createRouter(history, app, config, framework) {
1588
1602
  handler.unload(currentPage, stacks.length, true);
1589
1603
  }
1590
1604
  }
1591
- if (cacheTabs[handler.pathname]) {
1592
- stacks.popTab(handler.pathname);
1605
+ if (cacheTabs[pathname]) {
1606
+ stacks.popTab(pathname);
1593
1607
  return handler.show(stacks.getItem(0), pageConfig, 0);
1594
1608
  }
1595
1609
  shouldLoad = true;
@@ -17,6 +17,10 @@ function createRouter(history, app, config, framework) {
17
17
  }
18
18
  RouterConfig.config = config;
19
19
  const handler = new PageHandler(config, history);
20
+ // Note: 弱网情况下,快速切换 tab,会造成同个页面实例被多次挂在到页面上,原因是资源请求是异步的,短时间内发起多个请求,
21
+ // 会在资源加载完成后,同时走到挂载的逻辑,造成 pageStampId 更新不及时,两个 page 的Id 相同,后面很多操作是通过 getElementById 来进行的
22
+ // 所以需要加一个锁来应对这个情况
23
+ const pageLock = {};
20
24
  routesAlias.set(handler.router.customRoutes);
21
25
  const basename = handler.router.basename;
22
26
  const routes = handler.routes.map(route => {
@@ -40,24 +44,30 @@ function createRouter(history, app, config, framework) {
40
44
  app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
41
45
  const render = ({ location, action }) => __awaiter(this, void 0, void 0, function* () {
42
46
  var _c, _d, _e, _f, _g, _h, _j, _k;
43
- handler.pathname = decodeURI(location.pathname);
47
+ // Note: 由于下面有异步加载操作 先不要在这里去设置 handler.pathname
48
+ const currentPathname = decodeURI(location.pathname);
44
49
  if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
45
50
  window.scrollTo(0, 0);
46
51
  eventCenter.trigger('__taroRouterChange', {
47
52
  toLocation: {
48
- path: handler.pathname
53
+ path: currentPathname
49
54
  }
50
55
  });
51
- let element, params;
56
+ let element, context, params;
57
+ const routerPath = handler.router.forcePath || currentPathname;
58
+ pageLock[routerPath] = typeof pageLock[routerPath] === 'number' ? pageLock[routerPath] + 1 : 1;
59
+ const currentLock = pageLock[routerPath];
60
+ let postLock;
52
61
  try {
53
- const result = yield router.resolve(handler.router.forcePath || handler.pathname);
54
- [element, , params] = yield Promise.all(result);
62
+ const result = yield router.resolve(routerPath);
63
+ [element, context, params] = yield Promise.all(result);
64
+ postLock = pageLock[routerPath];
55
65
  }
56
66
  catch (error) {
57
67
  if (error.status === 404) {
58
68
  const notFoundEvent = {
59
69
  isEntryPage: stacks.length === 0,
60
- path: handler.pathname,
70
+ path: currentPathname,
61
71
  query: handler.getQuery(createStampId()),
62
72
  };
63
73
  (_d = app.onPageNotFound) === null || _d === void 0 ? void 0 : _d.call(app, notFoundEvent);
@@ -71,9 +81,12 @@ function createRouter(history, app, config, framework) {
71
81
  throw error;
72
82
  }
73
83
  }
74
- if (!element)
84
+ if (!element || currentLock !== postLock)
75
85
  return;
76
- const pageConfig = handler.pageConfig;
86
+ // Note: 异步结束后,在设置 handler.pathname
87
+ // context.pathname 在 universal-router 被处理过了,是发起资源请求的时候传入的 pathname,即 await router.resolve(routerPath) 这个 routerPath
88
+ handler.pathname = context.pathname;
89
+ const { pathname, pageConfig } = handler;
77
90
  let enablePullDownRefresh = ((_e = config === null || config === void 0 ? void 0 : config.window) === null || _e === void 0 ? void 0 : _e.enablePullDownRefresh) || false;
78
91
  let navigationStyle = ((_f = config === null || config === void 0 ? void 0 : config.window) === null || _f === void 0 ? void 0 : _f.navigationStyle) || 'default';
79
92
  let navigationBarTextStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationBarTextStyle) || 'white';
@@ -94,7 +107,6 @@ function createRouter(history, app, config, framework) {
94
107
  }
95
108
  eventCenter.trigger('__taroSetNavigationStyle', navigationStyle, navigationBarTextStyle, navigationBarBackgroundColor);
96
109
  const currentPage = Current.page;
97
- const pathname = handler.pathname;
98
110
  const methodName = (_j = stacks.method) !== null && _j !== void 0 ? _j : '';
99
111
  const cacheTabs = stacks.getTabs();
100
112
  let shouldLoad = false;
@@ -110,7 +122,7 @@ function createRouter(history, app, config, framework) {
110
122
  }
111
123
  shouldLoad = true;
112
124
  }
113
- else if (currentPage && handler.isTabBar(handler.pathname)) {
125
+ else if (currentPage && handler.isTabBar(pathname)) {
114
126
  if (handler.isSamePage(currentPage))
115
127
  return;
116
128
  if (handler.isTabBar(currentPage.path)) {
@@ -128,8 +140,8 @@ function createRouter(history, app, config, framework) {
128
140
  handler.unload(currentPage, stacks.length, true);
129
141
  }
130
142
  }
131
- if (cacheTabs[handler.pathname]) {
132
- stacks.popTab(handler.pathname);
143
+ if (cacheTabs[pathname]) {
144
+ stacks.popTab(pathname);
133
145
  return handler.show(stacks.getItem(0), pageConfig, 0);
134
146
  }
135
147
  shouldLoad = true;
package/dist/style.js CHANGED
@@ -4,7 +4,8 @@
4
4
  function loadAnimateStyle(ms = 300) {
5
5
  const css = `
6
6
  body {
7
- overflow: hidden; // 防止 iOS 页面滚动
7
+ /* 防止 iOS 页面滚动 */
8
+ overflow: hidden;
8
9
  }
9
10
  .taro_router > .taro_page {
10
11
  position: absolute;
@@ -131,7 +132,7 @@ function loadNavigationBarStyle() {
131
132
  to {
132
133
  transform: rotate(360deg);
133
134
  }
134
- }
135
+ }
135
136
 
136
137
  .taro-navigation-bar-no-icon > .taro-navigation-bar-home {
137
138
  display: none;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tarojs/router",
3
- "version": "3.6.30",
3
+ "version": "3.6.31-canary.1",
4
4
  "description": "Taro-router",
5
5
  "browser": "dist/index.js",
6
6
  "main:h5": "dist/index.esm.js",
@@ -44,14 +44,14 @@
44
44
  "rollup-plugin-ts": "^3.0.2",
45
45
  "ts-jest": "^29.0.5",
46
46
  "typescript": "^4.7.4",
47
- "@tarojs/runtime": "3.6.30",
48
- "@tarojs/shared": "3.6.30",
49
- "@tarojs/taro": "3.6.30"
47
+ "@tarojs/runtime": "3.6.31-canary.1",
48
+ "@tarojs/shared": "3.6.31-canary.1",
49
+ "@tarojs/taro": "3.6.31-canary.1"
50
50
  },
51
51
  "peerDependencies": {
52
- "@tarojs/runtime": "3.6.30",
53
- "@tarojs/shared": "3.6.30",
54
- "@tarojs/taro": "3.6.30"
52
+ "@tarojs/runtime": "3.6.31-canary.1",
53
+ "@tarojs/taro": "3.6.31-canary.1",
54
+ "@tarojs/shared": "3.6.31-canary.1"
55
55
  },
56
56
  "scripts": {
57
57
  "prebuild": "pnpm run clean",