@uniweb/runtime 0.5.1 → 0.5.3
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 +2 -2
- package/src/hooks/useRememberScroll.js +10 -7
- package/src/index.jsx +16 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniweb/runtime",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "Minimal runtime for loading Uniweb foundations",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"node": ">=20.19"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@uniweb/core": "0.3.
|
|
34
|
+
"@uniweb/core": "0.3.3"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@vitejs/plugin-react": "^4.5.2",
|
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
*
|
|
7
7
|
* Behavior:
|
|
8
8
|
* - Saves scroll position when navigating away from a page
|
|
9
|
-
* - Restores scroll position
|
|
10
|
-
* - Scrolls to top
|
|
9
|
+
* - Restores scroll position on back/forward (POP) navigation
|
|
10
|
+
* - Scrolls to top on new navigation (PUSH/REPLACE, e.g. link clicks)
|
|
11
11
|
* - Optionally resets block states on scroll restoration
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
import { useEffect, useRef } from 'react'
|
|
15
|
-
import { useLocation } from 'react-router-dom'
|
|
15
|
+
import { useLocation, useNavigationType } from 'react-router-dom'
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* useRememberScroll hook
|
|
@@ -26,6 +26,7 @@ export function useRememberScroll(options = {}) {
|
|
|
26
26
|
const { enabled = true, resetBlockStates = true, scrollDelay = 0 } = options
|
|
27
27
|
|
|
28
28
|
const location = useLocation()
|
|
29
|
+
const navigationType = useNavigationType()
|
|
29
30
|
const previousPathRef = useRef(location.pathname)
|
|
30
31
|
const isFirstRender = useRef(true)
|
|
31
32
|
|
|
@@ -62,16 +63,18 @@ export function useRememberScroll(options = {}) {
|
|
|
62
63
|
previousPage.scrollY = window.scrollY
|
|
63
64
|
}
|
|
64
65
|
|
|
65
|
-
//
|
|
66
|
+
// Determine scroll target:
|
|
67
|
+
// - POP (back/forward): restore saved position
|
|
68
|
+
// - PUSH/REPLACE (link click, programmatic): scroll to top
|
|
66
69
|
if (currentPage) {
|
|
67
|
-
const targetScroll = currentPage.scrollY || 0
|
|
70
|
+
const targetScroll = navigationType === 'POP' ? (currentPage.scrollY || 0) : 0
|
|
68
71
|
|
|
69
72
|
// Reset block states if requested (for animations, etc.)
|
|
70
73
|
if (resetBlockStates && typeof currentPage.resetBlockStates === 'function') {
|
|
71
74
|
currentPage.resetBlockStates()
|
|
72
75
|
}
|
|
73
76
|
|
|
74
|
-
//
|
|
77
|
+
// Apply scroll position
|
|
75
78
|
const restore = () => {
|
|
76
79
|
window.scrollTo(0, targetScroll)
|
|
77
80
|
}
|
|
@@ -86,7 +89,7 @@ export function useRememberScroll(options = {}) {
|
|
|
86
89
|
|
|
87
90
|
// Update previous path ref
|
|
88
91
|
previousPathRef.current = currentPath
|
|
89
|
-
}, [location.pathname, enabled, resetBlockStates, scrollDelay])
|
|
92
|
+
}, [location.pathname, navigationType, enabled, resetBlockStates, scrollDelay])
|
|
90
93
|
|
|
91
94
|
// Save scroll position before page unload
|
|
92
95
|
useEffect(() => {
|
package/src/index.jsx
CHANGED
|
@@ -246,6 +246,22 @@ function initUniweb(configData) {
|
|
|
246
246
|
// Set up icon resolver based on site config
|
|
247
247
|
uniwebInstance.iconResolver = createIconResolver(configData.icons)
|
|
248
248
|
|
|
249
|
+
// Populate icon cache from prerendered data (if available)
|
|
250
|
+
// This allows icons to render immediately without CDN fetches
|
|
251
|
+
if (typeof document !== 'undefined') {
|
|
252
|
+
try {
|
|
253
|
+
const cacheEl = document.getElementById('__ICON_CACHE__')
|
|
254
|
+
if (cacheEl) {
|
|
255
|
+
const cached = JSON.parse(cacheEl.textContent)
|
|
256
|
+
for (const [key, svg] of Object.entries(cached)) {
|
|
257
|
+
uniwebInstance.iconCache.set(key, svg)
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
} catch (e) {
|
|
261
|
+
// Ignore parse errors
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
249
265
|
return uniwebInstance
|
|
250
266
|
}
|
|
251
267
|
|