()
| 55 | } |
| 56 | |
| 57 | function useDelayedSnapshot() { |
| 58 | let [delayedSnapshot, setDelayedSnapshot] = useState(getSnapshot()); |
| 59 | let skeletonDisplayTime = useRef(0); |
| 60 | useEffect(() => { |
| 61 | let timeout; |
| 62 | return subscribe(() => { |
| 63 | clearTimeout(timeout); |
| 64 | |
| 65 | let snapshot = getSnapshot(); |
| 66 | if (snapshot.promise) { |
| 67 | // Delay skeleton slightly in case network is fast. |
| 68 | timeout = setTimeout(() => { |
| 69 | setDelayedSnapshot(snapshot); |
| 70 | }, SKELETON_DELAY); |
| 71 | } else { |
| 72 | // Ensure that skeleton shows for a minimum amount of time |
| 73 | // if it shows at all, to avoid a jarring flash. |
| 74 | let skeletonTimeout = skeletonDisplayTime.current + MIN_SKELETON_TIME - Date.now(); |
| 75 | if (skeletonTimeout > 0) { |
| 76 | timeout = setTimeout(() => { |
| 77 | setDelayedSnapshot(snapshot); |
| 78 | }, skeletonTimeout); |
| 79 | } else { |
| 80 | setDelayedSnapshot(snapshot); |
| 81 | } |
| 82 | } |
| 83 | }); |
| 84 | }, []); |
| 85 | |
| 86 | useEffect(() => { |
| 87 | if (delayedSnapshot.promise) { |
| 88 | skeletonDisplayTime.current = Date.now(); |
| 89 | } |
| 90 | }, [delayedSnapshot]); |
| 91 | |
| 92 | return delayedSnapshot; |
| 93 | } |
| 94 | |
| 95 | export function NavigationSuspense({children}: {children: React.ReactNode}) { |
| 96 | let {isLoading} = useContext(RouterContext)!; |
no test coverage detected