@ecopages/react-router 0.2.0-alpha.52 → 0.2.0-alpha.53
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/package.json +3 -3
- package/src/router.js +22 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecopages/react-router",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.53",
|
|
4
4
|
"description": "Client-side SPA router for EcoPages React applications",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ecopages",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"directory": "packages/react-router"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@ecopages/core": "0.2.0-alpha.
|
|
36
|
-
"@ecopages/react": "0.2.0-alpha.
|
|
35
|
+
"@ecopages/core": "0.2.0-alpha.53",
|
|
36
|
+
"@ecopages/react": "0.2.0-alpha.53"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"react": "^19.2.6",
|
package/src/router.js
CHANGED
|
@@ -56,6 +56,27 @@ function normalizeLayoutKey(value) {
|
|
|
56
56
|
return trimmed.split("#")[0]?.split("?")[0]?.replace(/\/$/, "") || "layout";
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
+
function hashString(value) {
|
|
60
|
+
let hash = 2166136261;
|
|
61
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
62
|
+
hash ^= value.charCodeAt(index);
|
|
63
|
+
hash = Math.imul(hash, 16777619);
|
|
64
|
+
}
|
|
65
|
+
return (hash >>> 0).toString(36);
|
|
66
|
+
}
|
|
67
|
+
function getLayoutSourceSignature(Layout) {
|
|
68
|
+
const source = Function.prototype.toString.call(Layout).replace(/\s+/g, " ").trim();
|
|
69
|
+
return hashString(source);
|
|
70
|
+
}
|
|
71
|
+
function getLayoutCacheKey(Layout) {
|
|
72
|
+
const layoutConfig = Layout.config;
|
|
73
|
+
const layoutMetaKey = layoutConfig?.__eco?.file || layoutConfig?.__eco?.id;
|
|
74
|
+
if (layoutMetaKey) {
|
|
75
|
+
return normalizeLayoutKey(layoutMetaKey);
|
|
76
|
+
}
|
|
77
|
+
const layoutNameKey = Layout.displayName || Layout.name || "layout";
|
|
78
|
+
return `${normalizeLayoutKey(layoutNameKey)}:${getLayoutSourceSignature(Layout)}`;
|
|
79
|
+
}
|
|
59
80
|
function clearLayoutCache() {
|
|
60
81
|
getLayoutCache().clear();
|
|
61
82
|
}
|
|
@@ -77,9 +98,7 @@ const PageContent = () => {
|
|
|
77
98
|
}
|
|
78
99
|
if (persistLayouts) {
|
|
79
100
|
const layoutCache = getLayoutCache();
|
|
80
|
-
const
|
|
81
|
-
const layoutKeyRaw = layoutConfig?.__eco?.id || Layout.displayName || Layout.name || "layout";
|
|
82
|
-
const layoutKey = normalizeLayoutKey(layoutKeyRaw);
|
|
101
|
+
const layoutKey = getLayoutCacheKey(Layout);
|
|
83
102
|
if (!layoutCache.has(layoutKey) || refreshPersistedLayout && layoutCache.get(layoutKey) !== Layout) {
|
|
84
103
|
layoutCache.set(layoutKey, Layout);
|
|
85
104
|
}
|