dumi 2.3.0-beta.4 → 2.3.0-beta.5
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.
|
@@ -8,6 +8,7 @@ import { getRouteMetaById, matchRoutes, useAppData, useLocation, useRouteData }
|
|
|
8
8
|
import { useCallback, useState } from 'react';
|
|
9
9
|
import { useIsomorphicLayoutEffect } from "./utils";
|
|
10
10
|
var cache = new Map();
|
|
11
|
+
var asyncCache = new Map();
|
|
11
12
|
var EMPTY_META = {
|
|
12
13
|
frontmatter: {},
|
|
13
14
|
toc: [],
|
|
@@ -16,7 +17,6 @@ var EMPTY_META = {
|
|
|
16
17
|
var ASYNC_META_PROPS = ['texts'];
|
|
17
18
|
function getCachedRouteMeta(route) {
|
|
18
19
|
var cacheKey = route.id;
|
|
19
|
-
var pendingCacheKey = "".concat(cacheKey, ":pending");
|
|
20
20
|
if (!cache.get(cacheKey)) {
|
|
21
21
|
var _meta$tabs;
|
|
22
22
|
var merge = function merge() {
|
|
@@ -34,15 +34,15 @@ function getCachedRouteMeta(route) {
|
|
|
34
34
|
}));
|
|
35
35
|
var proxyGetter = function proxyGetter(target, prop) {
|
|
36
36
|
if (ASYNC_META_PROPS.includes(prop)) {
|
|
37
|
-
if (!
|
|
37
|
+
if (!asyncCache.get(cacheKey)) {
|
|
38
38
|
// load async meta then replace cache
|
|
39
|
-
|
|
39
|
+
asyncCache.set(cacheKey, getRouteMetaById(route.id).then(function (full) {
|
|
40
40
|
return cache.set(cacheKey, merge(full)).get(cacheKey);
|
|
41
41
|
}));
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
// throw promise to trigger suspense
|
|
45
|
-
throw
|
|
45
|
+
throw asyncCache.get(cacheKey);
|
|
46
46
|
}
|
|
47
47
|
return target[prop];
|
|
48
48
|
};
|
|
@@ -138,8 +138,8 @@ export function getRouteMetaById<T extends { syncOnly?: boolean }>(
|
|
|
138
138
|
id: string,
|
|
139
139
|
opts?: T,
|
|
140
140
|
): T extends { syncOnly: true }
|
|
141
|
-
?
|
|
142
|
-
: Promise<
|
|
141
|
+
? IRouteMeta | undefined
|
|
142
|
+
: Promise<IRouteMeta> | undefined {
|
|
143
143
|
if (filesMeta[id]) {
|
|
144
144
|
const { frontmatter, toc, textGetter, tabs } = filesMeta[id];
|
|
145
145
|
const routeMeta: IRouteMeta = {
|