Repository navigation
Conversation
|
@parasharrajat Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
|
Sorry, accidently mistaken, apologize for that! |
| // `new URL(..., window.location.origin)`), so the Cache API resolves them | ||
| // consistently regardless of the active route. Prefixing here would race with | ||
| // async environment resolution and diverge from main's key scheme. | ||
| function put(cacheName: CacheNameType, key: string, value: Response) { |
There was a problem hiding this comment.
❌ CONSISTENCY-3 (docs)
The same Cache API availability guard (if (!('caches' in window)) { Log.warn('Cache API is not supported'); return; }, plus the identical // Exit early if the Cache API is not available in the current browser. comment) is now copy-pasted into put, get, remove, and clear (and already lives in init). This duplicated logic increases maintenance overhead and bug risk.
Extract the check into a single helper and reuse it:
function isCacheAPIAvailable(): boolean {
if (!('caches' in window)) {
Log.warn('Cache API is not supported');
return false;
}
return true;
}
function put(cacheName: CacheNameType, key: string, value: Response) {
if (!isCacheAPIAvailable()) {
return;
}
return caches.open(cacheName).then((cache) => cache.put(key, value));
}Reviewed at: 2b66558 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
| * | ||
| * This replaces the old `moveReceiptToDurableStorage` + `Receipts-Upload` path. Staging into the | ||
| * same directory that `cacheAttachment` later caches into lets `cacheAttachment` reuse the file | ||
| * instead of copying it again — which is what eliminates the duplicate on disk. |
There was a problem hiding this comment.
❌ CONSISTENCY-16 (docs)
This comment uses an em dash, which the plain-comment-style rule flags. Comments should read as plain sentences.
Rewrite without the em dash, for example:
* same directory that `cacheAttachment` later caches into lets `cacheAttachment` reuse the file
* instead of copying it again, which is what eliminates the duplicate on disk.Reviewed at: 2b66558 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
| if (exists) { | ||
| return localUri.startsWith('file://') ? localUri : `file://${localUri}`; | ||
| } | ||
| // File no longer exists — remove stale entry and fall through |
There was a problem hiding this comment.
❌ CONSISTENCY-16 (docs)
This comment uses an em dash, which the plain-comment-style rule flags. Comments should read as plain sentences.
Rewrite without the em dash, for example:
// File no longer exists, so remove the stale entry and fall throughReviewed at: 2b66558 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
| @@ -0,0 +1,119 @@ | |||
| import {AttachmentIDContext} from '@components/Attachments/AttachmentIDContext'; | |||
There was a problem hiding this comment.
❌ CONSISTENCY-14 (docs)
This new, non-trivial hook file (119 lines) opens straight into imports with no header comment describing what it does. The previous useCachedAttachmentSource.ts it replaces carried a detailed header explaining the optimistic-local/cache resolution behavior; that context is now lost.
Add a short header describing the file's purpose, for example:
/**
* Resolves the displayed source for an attachment, reading cached bytes back into a fresh object URL
* when the persisted source is a stale local/optimistic URI, and falling back to the original source otherwise.
*/
import {AttachmentIDContext} from '@components/Attachments/AttachmentIDContext';Reviewed at: 2b66558 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
| {/* Empty View matching gallery size so justifyContentAround keeps the shutter exactly centered - it's the simplest solution */} | ||
| <View style={{width: variables.iconSizeMenuItem, height: variables.iconSizeMenuItem}} /> | ||
| <View | ||
| style={{ |
There was a problem hiding this comment.
❌ UI-3 (docs)
This JSX passes an inline style object literal (style={{width: variables.iconSizeMenuItem, height: variables.iconSizeMenuItem}}) to a style-typed prop. Inline objects create a new object every render and bypass the shared style system. The values are static and belong in styles/StyleUtils.
Use a StyleUtils helper (or an array of styles) instead, for example:
<View style={StyleUtils.getWidthAndHeightStyle(variables.iconSizeMenuItem, variables.iconSizeMenuItem)} />Reviewed at: 2b66558 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2b66558e4c
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const existingSource = attachmentLocalSources.get(attachmentID); | ||
| if (existingSource) { | ||
| return existingSource; |
There was a problem hiding this comment.
Key cached blobs by source as well as attachment ID
On web, this attachment-level hit returns whatever blob was first cached for the ID without checking that it was cached for the current URI. A report thumbnail and the full-size attachment share the same attachmentID but use different URLs; after the thumbnail renders first, opening the attachment modal with the full URL will reuse the thumbnail blob from attachmentLocalSources, so users can see a low-resolution or wrong preview until the cache is cleared. Include the source/variant in the in-memory/cache key, or verify the cached entry matches the requested URI before returning it.
Useful? React with 👍 / 👎.
# Conflicts: # src/components/AttachmentPicker/index.native.tsx # src/libs/fileDownload/checkFileExists/index.ts # src/pages/iou/request/step/IOURequestStepOdometerImage/index.native.tsx # src/pages/iou/request/step/IOURequestStepScan/components/Camera/index.native.tsx # src/pages/media/AttachmentModalScreen/routes/TransactionReceiptModalContent.tsx # tests/unit/hooks/useCachedImageSource.test.ts
ReceiptStorage now owns the same attachments/ folder as stageAttachment, so a staged file is never copied a second time. getReceiptsUploadFolderPath and RECEIPTS_UPLOAD_PATH are gone. Stored paths that still name the legacy Receipts-Upload folder keep resolving, and adopt migrates such files into the attachments folder on first touch.
|
See here, closing as the issue has changed since work began here. |
Explanation of Change
Fixed Issues
$ #84964
$ #85604
PROPOSAL: #9402 (comment)
Tests
Offline tests
Same as tests
QA Steps
Same as tests
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*files and using the translation methodSTYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari