Skip to content

Commit d9ae4c8

Browse files
committed
style: format code and add consistent string quotes in img-file.ts
1 parent 90058c8 commit d9ae4c8

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

use-fireproof/react/img-file.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ async function loadFile({
8383
? getCacheKey(fileData) // Already includes 'file:' prefix
8484
: null;
8585
const isDifferentFile = currentKey !== newKey;
86-
86+
8787
// If same content key, check if we have a cached URL we can reuse
8888
const canReuseCache = !isDifferentFile && newKey && objectUrlCache.has(newKey);
8989

@@ -105,7 +105,7 @@ async function loadFile({
105105
URL.revokeObjectURL(objectUrlCache.get(newKey) as string);
106106
objectUrlCache.delete(newKey);
107107
}
108-
}
108+
},
109109
};
110110
keyRef.current = newKey;
111111
if (prevCleanup && prevCleanup.revoke) {
@@ -114,7 +114,7 @@ async function loadFile({
114114

115115
return newCleanupObj;
116116
}
117-
117+
118118
// Handle same content key - reuse existing cached URL if available
119119
if (canReuseCache && newKey) {
120120
const src = objectUrlCache.get(newKey) as string;
@@ -138,7 +138,6 @@ export function ImgFile({ file, meta, ...imgProps }: ImgFileProps) {
138138
const keyRef = useRef<string | null>(null);
139139
const nextFileDataRef = useRef<FileType | undefined>(undefined);
140140

141-
142141
// Use meta as fallback if file is not provided (for backward compatibility)
143142
// Memoize fileData to prevent unnecessary re-renders
144143
const fileData = useMemo(() => {
@@ -153,8 +152,7 @@ export function ImgFile({ file, meta, ...imgProps }: ImgFileProps) {
153152
useEffect(() => {
154153
if (!fileData) return;
155154
let isMounted = true;
156-
157-
155+
158156
loadFile({ fileData, fileObjRef, cleanupRef, setImgDataUrl, keyRef }).then(function handleResult(result) {
159157
if (isMounted) {
160158
// Store the result in cleanupRef.current if component is still mounted
@@ -167,11 +165,11 @@ export function ImgFile({ file, meta, ...imgProps }: ImgFileProps) {
167165

168166
return function cleanupEffect() {
169167
isMounted = false;
170-
168+
171169
// Content-aware conditional cleanup: only revoke URLs when content actually changes
172170
if (cleanupRef.current) {
173171
const currentContentKey = cleanupRef.current.contentKey;
174-
172+
175173
// Compute next content key from the upcoming fileData (same logic as in loadFile)
176174
let nextContentKey = null;
177175
const upcomingFileData = nextFileDataRef.current;
@@ -182,20 +180,20 @@ export function ImgFile({ file, meta, ...imgProps }: ImgFileProps) {
182180
nextContentKey = `file:${upcomingFileData.name}-${upcomingFileData.size}-${upcomingFileData.lastModified}`;
183181
}
184182
}
185-
183+
186184
// Different cleanup logic for File vs DocFileMeta objects:
187185
// - File objects: Always cleanup on effect change (including unmount)
188186
// - DocFileMeta objects: Only cleanup when CID actually changes
189187
const isContentChanging = currentContentKey !== nextContentKey;
190-
const isFileObject = currentContentKey?.startsWith('file:');
191-
const isDocFileMetaObject = currentContentKey?.startsWith('cid:');
192-
188+
const isFileObject = currentContentKey?.startsWith("file:");
189+
const isDocFileMetaObject = currentContentKey?.startsWith("cid:");
190+
193191
const shouldCleanup = isFileObject || (isDocFileMetaObject && isContentChanging);
194-
192+
195193
if (shouldCleanup && cleanupRef.current.revoke) {
196194
cleanupRef.current.revoke();
197195
}
198-
196+
199197
cleanupRef.current = null;
200198
}
201199
};

0 commit comments

Comments
 (0)