fix: 消除 buildOrderStatusUrl 重复定义,修复轮询回调引用稳定性
- 将 buildOrderStatusUrl 提取到 status-url.ts(客户端安全模块), 删除 OrderStatus/PaymentQRCode/result 三处重复定义 - OrderStatus.tsx 轮询 effect 使用 useRef 保存 onStateChange, 避免非 memoized 回调导致定时器不断重建 - result/page.tsx 增加 accessToken 最小长度校验, 避免无效参数触发无意义的 API 请求
This commit is contained in:
15
src/lib/order/status-url.ts
Normal file
15
src/lib/order/status-url.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* Client-safe utility for building order status API URLs.
|
||||
* This module must NOT import any server-only modules (config, fs, crypto, etc.).
|
||||
*/
|
||||
|
||||
const ACCESS_TOKEN_KEY = 'access_token';
|
||||
|
||||
export function buildOrderStatusUrl(orderId: string, accessToken?: string | null): string {
|
||||
const query = new URLSearchParams();
|
||||
if (accessToken) {
|
||||
query.set(ACCESS_TOKEN_KEY, accessToken);
|
||||
}
|
||||
const suffix = query.toString();
|
||||
return suffix ? `/api/orders/${orderId}?${suffix}` : `/api/orders/${orderId}`;
|
||||
}
|
||||
Reference in New Issue
Block a user