Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix crash attachment #34030

Merged
merged 2 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/AttachmentModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function AttachmentModal(props) {
const [isAuthTokenRequired, setIsAuthTokenRequired] = useState(props.isAuthTokenRequired);
const [attachmentInvalidReasonTitle, setAttachmentInvalidReasonTitle] = useState('');
const [attachmentInvalidReason, setAttachmentInvalidReason] = useState(null);
const [source, setSource] = useState(props.source);
const [source, setSource] = useState(() => props.source);
const [modalType, setModalType] = useState(CONST.MODAL.MODAL_TYPE.CENTERED_UNSWIPEABLE);
const [isConfirmButtonDisabled, setIsConfirmButtonDisabled] = useState(false);
const [confirmButtonFadeAnimation] = useState(() => new Animated.Value(1));
Expand Down Expand Up @@ -359,7 +359,7 @@ function AttachmentModal(props) {
}, []);

useEffect(() => {
setSource(props.source);
setSource(() => props.source);
}, [props.source]);

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ReceiptUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function getThumbnailAndImageURIs(transaction: Transaction, receiptPath: string
image = ReceiptSVG;
}

const isLocalFile = typeof path === 'number' || path.startsWith('blob:') || path.startsWith('file:');
const isLocalFile = typeof path === 'number' || path.startsWith('blob:') || path.startsWith('file:') || path === ReceiptGeneric;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is type of ReceiptGeneric?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah it's string.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok confirmed string on web, number on native.
So Case 1 bug is supposed to happen only on web

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm doesn't this apply to all paths that have a local file then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think if we check isLocalFile we should use this, currently I see we build the isLocalFile only in this function getThumbnailAndImageURIs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we apply a more hollistic approach to isLocalFile though? I imagine in the future we'll have more web assets we pass into getThumbnailAndImageURIs and ideally we don't just add an if check for each path. Maybe we can check if it starts with '/'? What do you think

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think it is good, we can modify it like that to cover all we assets' path:

const isLocalFile = ... path.startsWith('/');

return {thumbnail: image, image: path, isLocalFile};
}

Expand Down
Loading