@hsu-react/ui 2.5.1 → 2.5.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.
@@ -143,22 +143,29 @@ export var useTabPath = function useTabPath(_ref) {
143
143
  }, [location.pathname, location.search]);
144
144
 
145
145
  /**
146
- * Closing the last tab navigates to `basePath` — but when that tab *was* `basePath`, the
147
- * location never changes, so path matching would not re-run and the bar would be left empty
148
- * while its page is still on screen. Going empty has to re-trigger the match on its own.
146
+ * 路径匹配只跟着**地址**跑,不跟着 openKeys 的空/非空跑。
149
147
  *
150
- * This settles rather than looping: re-matching adds the tab back, which flips `isEmpty` and
151
- * runs the effect once more, and that pass finds the tab already present and returns the same
152
- * state object — so React stops there. (Only true because the setters below bail out when
153
- * nothing changed; without that this would spin.)
148
+ * 这里原本还挂了一个 `isEmpty` 依赖:openKeys 一变空就重跑一次匹配,用意是补上
149
+ * 「关掉的正是 basePath 那一页 navigate(basePath) 不改变地址 匹配不会重跑」
150
+ * 这一档。但它会把**刚关掉的那个页签原样加回来**:
151
+ *
152
+ * 关闭按钮里 `setOpenkeys([])` 是默认优先级的更新,而 `navigate()` 引起的
153
+ * location 变更走的是 router 的低优先级更新(startTransition / deferred 路由表)。
154
+ * React 先提交前者,此时 `useLocation()` 还停在**被关掉的那一页**,本 effect 因
155
+ * `isEmpty` 翻转而跑了一遍,匹配到的自然还是它,于是页签复活;等 location 真正
156
+ * 落地,匹配又把目标页加成第二个页签。用户看到的就是「点一次关不掉,还多出一个」,
157
+ * 非得再点一次。
158
+ *
159
+ * 所以不补那一档:**页签栏空着是合法状态**。关掉最后一个页签时,若目标地址与当前
160
+ * 地址不同,location 变化自会把目标页签匹配出来;若相同(关掉的就是 basePath),
161
+ * 页签栏就空着,内容区仍是 basePath 那一页 —— 一次点击、不复活、不空白。
154
162
  */
155
- var isEmpty = openKeys.length === 0;
156
163
  useEffect(function () {
157
164
  // Handle affixed routes first to populate openKeys
158
165
  _checkAffix(items);
159
166
  // Then run path matching
160
167
  _checkPath(items);
161
- }, [_checkAffix, _checkPath, items, isEmpty]);
168
+ }, [_checkAffix, _checkPath, items]);
162
169
  return {
163
170
  tabKey: tabKey,
164
171
  setTabKey: setTabKey,
@@ -116,22 +116,29 @@ const useTabPath = ({
116
116
  }, [location.pathname, location.search]);
117
117
 
118
118
  /**
119
- * Closing the last tab navigates to `basePath` — but when that tab *was* `basePath`, the
120
- * location never changes, so path matching would not re-run and the bar would be left empty
121
- * while its page is still on screen. Going empty has to re-trigger the match on its own.
119
+ * 路径匹配只跟着**地址**跑,不跟着 openKeys 的空/非空跑。
122
120
  *
123
- * This settles rather than looping: re-matching adds the tab back, which flips `isEmpty` and
124
- * runs the effect once more, and that pass finds the tab already present and returns the same
125
- * state object — so React stops there. (Only true because the setters below bail out when
126
- * nothing changed; without that this would spin.)
121
+ * 这里原本还挂了一个 `isEmpty` 依赖:openKeys 一变空就重跑一次匹配,用意是补上
122
+ * 「关掉的正是 basePath 那一页 navigate(basePath) 不改变地址 匹配不会重跑」
123
+ * 这一档。但它会把**刚关掉的那个页签原样加回来**:
124
+ *
125
+ * 关闭按钮里 `setOpenkeys([])` 是默认优先级的更新,而 `navigate()` 引起的
126
+ * location 变更走的是 router 的低优先级更新(startTransition / deferred 路由表)。
127
+ * React 先提交前者,此时 `useLocation()` 还停在**被关掉的那一页**,本 effect 因
128
+ * `isEmpty` 翻转而跑了一遍,匹配到的自然还是它,于是页签复活;等 location 真正
129
+ * 落地,匹配又把目标页加成第二个页签。用户看到的就是「点一次关不掉,还多出一个」,
130
+ * 非得再点一次。
131
+ *
132
+ * 所以不补那一档:**页签栏空着是合法状态**。关掉最后一个页签时,若目标地址与当前
133
+ * 地址不同,location 变化自会把目标页签匹配出来;若相同(关掉的就是 basePath),
134
+ * 页签栏就空着,内容区仍是 basePath 那一页 —— 一次点击、不复活、不空白。
127
135
  */
128
- const isEmpty = openKeys.length === 0;
129
136
  (0, _react.useEffect)(() => {
130
137
  // Handle affixed routes first to populate openKeys
131
138
  _checkAffix(items);
132
139
  // Then run path matching
133
140
  _checkPath(items);
134
- }, [_checkAffix, _checkPath, items, isEmpty]);
141
+ }, [_checkAffix, _checkPath, items]);
135
142
  return {
136
143
  tabKey,
137
144
  setTabKey,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hsu-react/ui",
3
- "version": "2.5.1",
3
+ "version": "2.5.2",
4
4
  "description": "一套基于 React + Ant Design 的中后台业务组件库",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -129,23 +129,29 @@ export const useTabPath = ({ items, affixRouter }: UseTabPathOptions) => {
129
129
  );
130
130
 
131
131
  /**
132
- * Closing the last tab navigates to `basePath` — but when that tab *was* `basePath`, the
133
- * location never changes, so path matching would not re-run and the bar would be left empty
134
- * while its page is still on screen. Going empty has to re-trigger the match on its own.
132
+ * 路径匹配只跟着**地址**跑,不跟着 openKeys 的空/非空跑。
135
133
  *
136
- * This settles rather than looping: re-matching adds the tab back, which flips `isEmpty` and
137
- * runs the effect once more, and that pass finds the tab already present and returns the same
138
- * state object — so React stops there. (Only true because the setters below bail out when
139
- * nothing changed; without that this would spin.)
134
+ * 这里原本还挂了一个 `isEmpty` 依赖:openKeys 一变空就重跑一次匹配,用意是补上
135
+ * 「关掉的正是 basePath 那一页 navigate(basePath) 不改变地址 匹配不会重跑」
136
+ * 这一档。但它会把**刚关掉的那个页签原样加回来**:
137
+ *
138
+ * 关闭按钮里 `setOpenkeys([])` 是默认优先级的更新,而 `navigate()` 引起的
139
+ * location 变更走的是 router 的低优先级更新(startTransition / deferred 路由表)。
140
+ * React 先提交前者,此时 `useLocation()` 还停在**被关掉的那一页**,本 effect 因
141
+ * `isEmpty` 翻转而跑了一遍,匹配到的自然还是它,于是页签复活;等 location 真正
142
+ * 落地,匹配又把目标页加成第二个页签。用户看到的就是「点一次关不掉,还多出一个」,
143
+ * 非得再点一次。
144
+ *
145
+ * 所以不补那一档:**页签栏空着是合法状态**。关掉最后一个页签时,若目标地址与当前
146
+ * 地址不同,location 变化自会把目标页签匹配出来;若相同(关掉的就是 basePath),
147
+ * 页签栏就空着,内容区仍是 basePath 那一页 —— 一次点击、不复活、不空白。
140
148
  */
141
- const isEmpty = openKeys.length === 0;
142
-
143
149
  useEffect(() => {
144
150
  // Handle affixed routes first to populate openKeys
145
151
  _checkAffix(items);
146
152
  // Then run path matching
147
153
  _checkPath(items);
148
- }, [_checkAffix, _checkPath, items, isEmpty]);
154
+ }, [_checkAffix, _checkPath, items]);
149
155
 
150
156
  return { tabKey, setTabKey, openKeys, setOpenkeys };
151
157
  };