Moves the app to TanStack Start with prerendering
Every page is now built as HTML from sitePages.ts, with a catch-all route for 404.html. Hooks that read the browser during render are safe for prerendering. The script step that keeps the CSP intact follows, so this build still has inline scripts and is not deployable yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { useEffect, useRef, useState, useSyncExternalStore } from 'react';
|
||||
|
||||
const noopSubscribe = () => () => {};
|
||||
|
||||
type UseInViewOptions = {
|
||||
threshold?: number;
|
||||
@@ -8,21 +10,25 @@ type UseInViewOptions = {
|
||||
};
|
||||
|
||||
// Tells whether an element has come into (or near) the viewport, once.
|
||||
// Without IntersectionObserver the element counts as in view right away, so
|
||||
// content is never left hidden or unloaded.
|
||||
// Without IntersectionObserver the element counts as in view (from the first
|
||||
// render after hydration), so content is never left hidden or unloaded.
|
||||
export default function useInView<T extends Element>({
|
||||
threshold = 0,
|
||||
rootMargin = '0px',
|
||||
skip = false,
|
||||
}: UseInViewOptions = {}) {
|
||||
const ref = useRef<T>(null);
|
||||
const supported = typeof IntersectionObserver !== 'undefined';
|
||||
// The server cannot know, so prerender and hydration both assume support
|
||||
const unsupported = useSyncExternalStore(
|
||||
noopSubscribe,
|
||||
() => typeof IntersectionObserver === 'undefined',
|
||||
() => false,
|
||||
);
|
||||
const [intersected, setIntersected] = useState(false);
|
||||
const immediate = skip || !supported;
|
||||
|
||||
useEffect(() => {
|
||||
const element = ref.current;
|
||||
if (!element || immediate || intersected) return;
|
||||
if (!element || skip || unsupported || intersected) return;
|
||||
|
||||
const observer = new IntersectionObserver(
|
||||
(entries) => {
|
||||
@@ -36,7 +42,7 @@ export default function useInView<T extends Element>({
|
||||
observer.observe(element);
|
||||
|
||||
return () => observer.disconnect();
|
||||
}, [immediate, intersected, threshold, rootMargin]);
|
||||
}, [skip, unsupported, intersected, threshold, rootMargin]);
|
||||
|
||||
return { ref, inView: immediate || intersected };
|
||||
return { ref, inView: skip || intersected || unsupported };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user