mirror of
https://github.com/jeffvli/feishin.git
synced 2026-06-10 22:32:17 +02:00
Revert "fix NativeImage state causing crashes in table"
This reverts commit 4008c8dfdf.
This commit is contained in:
@@ -26,11 +26,8 @@ export function useNativeImage({
|
||||
const loadedRequestSignatureRef = useRef<null | string>(null);
|
||||
const objectUrlRef = useRef<null | string>(null);
|
||||
const onFetchErrorRef = useRef(onFetchError);
|
||||
const requestRef = useRef(request);
|
||||
const [state, setState] = useState<NativeImageState>({ status: 'idle' });
|
||||
|
||||
requestRef.current = request;
|
||||
|
||||
const requestSignature = useMemo(() => {
|
||||
if (!request) {
|
||||
return null;
|
||||
@@ -47,8 +44,6 @@ export function useNativeImage({
|
||||
onFetchErrorRef.current = onFetchError;
|
||||
|
||||
useEffect(() => {
|
||||
const request = requestRef.current;
|
||||
|
||||
const abortCurrentRequest = () => {
|
||||
abortControllerRef.current?.abort();
|
||||
abortControllerRef.current = null;
|
||||
@@ -67,61 +62,28 @@ export function useNativeImage({
|
||||
if (!request || !requestSignature) {
|
||||
abortCurrentRequest();
|
||||
revokeObjectUrl();
|
||||
setState((currentState) => {
|
||||
if (currentState.status === 'idle' && !currentState.displaySrc) {
|
||||
return currentState;
|
||||
}
|
||||
|
||||
return { status: 'idle' };
|
||||
});
|
||||
setState({ status: 'idle' });
|
||||
return;
|
||||
}
|
||||
|
||||
if (!enabled) {
|
||||
abortCurrentRequest();
|
||||
setState((currentState) => {
|
||||
if (currentState.displaySrc) {
|
||||
if (currentState.status === 'loaded') {
|
||||
return currentState;
|
||||
}
|
||||
|
||||
return { ...currentState, status: 'loaded' };
|
||||
}
|
||||
|
||||
if (currentState.status === 'idle' && !currentState.displaySrc) {
|
||||
return currentState;
|
||||
}
|
||||
|
||||
return { status: 'idle' };
|
||||
});
|
||||
setState((currentState) =>
|
||||
currentState.displaySrc
|
||||
? { ...currentState, status: 'loaded' }
|
||||
: { status: 'idle' },
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (loadedRequestSignatureRef.current === requestSignature && objectUrlRef.current) {
|
||||
const cachedObjectUrl = objectUrlRef.current;
|
||||
|
||||
setState((currentState) => {
|
||||
if (
|
||||
currentState.status === 'loaded' &&
|
||||
currentState.displaySrc === cachedObjectUrl
|
||||
) {
|
||||
return currentState;
|
||||
}
|
||||
|
||||
return { displaySrc: cachedObjectUrl, status: 'loaded' };
|
||||
});
|
||||
setState({ displaySrc: objectUrlRef.current, status: 'loaded' });
|
||||
return;
|
||||
}
|
||||
|
||||
abortCurrentRequest();
|
||||
revokeObjectUrl();
|
||||
setState((currentState) => {
|
||||
if (currentState.status === 'loading' && !currentState.displaySrc) {
|
||||
return currentState;
|
||||
}
|
||||
|
||||
return { status: 'loading' };
|
||||
});
|
||||
setState({ status: 'loading' });
|
||||
|
||||
const abortController = new AbortController();
|
||||
abortControllerRef.current = abortController;
|
||||
@@ -176,7 +138,7 @@ export function useNativeImage({
|
||||
abortControllerRef.current = null;
|
||||
}
|
||||
};
|
||||
}, [enabled, fetchPriority, requestSignature]);
|
||||
}, [enabled, fetchPriority, request, requestSignature]);
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
|
||||
Reference in New Issue
Block a user