@ubean/pages 0.5.2 → 0.6.0-beta.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/index.d.ts +5 -2
- package/dist/index.js +17 -16
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -359,13 +359,16 @@ interface UseDeferredDataResult<T> {
|
|
|
359
359
|
* 在组件中使用延迟数据。
|
|
360
360
|
*
|
|
361
361
|
* - **SSR**: 注册 promise 但不阻塞渲染,组件渲染 fallback;渲染完成后数据流式注入
|
|
362
|
-
* - **客户端水合**:
|
|
362
|
+
* - **客户端水合**: 首帧与 SSR 一致(仍是 fallback),挂载后再采用 `__UBEAN_DEFERRED__` 里的数据
|
|
363
|
+
* (不发第二次请求);**不能**在 setup 里就应用 —— 那会让客户端首帧与 SSR 的 DOM 不同,
|
|
364
|
+
* Vue 报 hydration mismatch,且被匹配上的元素会留下 SSR 的旧属性(实测 class 没被更新)
|
|
363
365
|
* - **客户端导航**: 调用 factory 获取数据,显示 pending → resolved
|
|
364
366
|
*
|
|
365
367
|
* @example
|
|
366
368
|
* ```vue
|
|
367
369
|
* <script setup>
|
|
368
|
-
*
|
|
370
|
+
* // 页面/组件在客户端图里,从 `ubean/client` 导入(不要从聚合入口 `ubean`)
|
|
371
|
+
* import { defer, useDeferredData } from 'ubean/client';
|
|
369
372
|
*
|
|
370
373
|
* const { data: comments, pending } = useDeferredData(
|
|
371
374
|
* 'comments',
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ref, shallowRef } from "vue";
|
|
1
|
+
import { getCurrentInstance, onMounted, ref, shallowRef } from "vue";
|
|
2
2
|
//#region src/protocol.ts
|
|
3
3
|
const PAGE_DATA_ID = "__UBEAN_PAGE_DATA__";
|
|
4
4
|
const LOCALE_DATA_ID = "__UBEAN_LOCALE__";
|
|
@@ -853,13 +853,16 @@ function __resetDeferredCache() {
|
|
|
853
853
|
* 在组件中使用延迟数据。
|
|
854
854
|
*
|
|
855
855
|
* - **SSR**: 注册 promise 但不阻塞渲染,组件渲染 fallback;渲染完成后数据流式注入
|
|
856
|
-
* - **客户端水合**:
|
|
856
|
+
* - **客户端水合**: 首帧与 SSR 一致(仍是 fallback),挂载后再采用 `__UBEAN_DEFERRED__` 里的数据
|
|
857
|
+
* (不发第二次请求);**不能**在 setup 里就应用 —— 那会让客户端首帧与 SSR 的 DOM 不同,
|
|
858
|
+
* Vue 报 hydration mismatch,且被匹配上的元素会留下 SSR 的旧属性(实测 class 没被更新)
|
|
857
859
|
* - **客户端导航**: 调用 factory 获取数据,显示 pending → resolved
|
|
858
860
|
*
|
|
859
861
|
* @example
|
|
860
862
|
* ```vue
|
|
861
863
|
* <script setup>
|
|
862
|
-
*
|
|
864
|
+
* // 页面/组件在客户端图里,从 `ubean/client` 导入(不要从聚合入口 `ubean`)
|
|
865
|
+
* import { defer, useDeferredData } from 'ubean/client';
|
|
863
866
|
*
|
|
864
867
|
* const { data: comments, pending } = useDeferredData(
|
|
865
868
|
* 'comments',
|
|
@@ -879,25 +882,23 @@ function useDeferredData(key, deferred) {
|
|
|
879
882
|
const data = shallowRef(void 0);
|
|
880
883
|
const pending = ref(true);
|
|
881
884
|
const error = shallowRef(null);
|
|
882
|
-
if (typeof window === "undefined")
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
if (cached !== void 0) {
|
|
888
|
-
if (cached !== null && typeof cached === "object" && "__deferredError" in cached) error.value = new Error(String(cached.__deferredError));
|
|
889
|
-
else data.value = cached;
|
|
890
|
-
pending.value = false;
|
|
891
|
-
} else {
|
|
892
|
-
pending.value = true;
|
|
893
|
-
deferred.factory().then((result) => {
|
|
885
|
+
if (typeof window === "undefined") __registerDeferred(key, deferred.factory());
|
|
886
|
+
else {
|
|
887
|
+
const adopt = () => {
|
|
888
|
+
const cached = readClientCache()?.[key];
|
|
889
|
+
if (cached === void 0) return deferred.factory().then((result) => {
|
|
894
890
|
data.value = result;
|
|
895
891
|
pending.value = false;
|
|
896
892
|
}).catch((err) => {
|
|
897
893
|
error.value = err instanceof Error ? err : new Error(String(err));
|
|
898
894
|
pending.value = false;
|
|
899
895
|
});
|
|
900
|
-
|
|
896
|
+
if (cached !== null && typeof cached === "object" && "__deferredError" in cached) error.value = new Error(String(cached.__deferredError));
|
|
897
|
+
else data.value = cached;
|
|
898
|
+
pending.value = false;
|
|
899
|
+
};
|
|
900
|
+
if (getCurrentInstance()) onMounted(adopt);
|
|
901
|
+
else queueMicrotask(adopt);
|
|
901
902
|
}
|
|
902
903
|
return {
|
|
903
904
|
data,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ubean/pages",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0-beta.1",
|
|
4
4
|
"description": "Page data protocol and isomorphic data layer for ubean (PageObject, useData, invalidateData)",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@ubean/shared": "0.
|
|
19
|
+
"@ubean/shared": "0.6.0-beta.1"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/node": "^26.5.0",
|