Repository navigation
fix(mobile): markdown images no longer shake on Android #27943
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -192,7 +192,16 @@ export function ThreadMarkdownImageView(props: { | |
| key={props.sourceKey} | ||
| uri={props.uri} | ||
| cacheKey={props.cacheKey} | ||
| onLoad={(size) => setDecoded({ sourceKey: props.sourceKey, size })} | ||
| onLoad={(size) => | ||
| // Only the first decode counts: later loads report the bitmap | ||
| // downsampled for the current frame (969 vs 970 wide), so keeping | ||
| // them resizes the frame, which reloads the image, and so on. | ||
| setDecoded((current) => | ||
| current?.sourceKey === props.sourceKey | ||
| ? current | ||
| : { sourceKey: props.sourceKey, size }, | ||
| ) | ||
| } | ||
| onError={() => setFailure({ uri: props.uri, failed: true })} | ||
| /> | ||
| )} | ||
|
|
@@ -269,6 +278,18 @@ export function ThreadMarkdownImage(props: { | |
| }) { | ||
| const withGallery = useFilePreviewGallery(); | ||
| const assetUrl = useAssetUrlState(props.environmentId, props.resource); | ||
| const resourceKey = | ||
| props.resource._tag === "attachment" | ||
| ? `attachment:${props.resource.attachmentId}` | ||
| : props.resource._tag === "tool-output-image" | ||
| ? `tool-output:${props.resource.itemId}:${props.resource.index}` | ||
| : `workspace:${props.resource.path}`; | ||
| // The view keeps the first decoded size per key, so a file edited in place needs a | ||
| // new key; a re-signed URL for the same revision must not get one. | ||
| const sourceKey = | ||
| assetUrl._tag === "Success" && assetUrl.fileRevision !== undefined | ||
| ? `${resourceKey}@${assetUrl.fileRevision}` | ||
| : resourceKey; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| return ( | ||
| <ThreadMarkdownImageView | ||
|
|
@@ -278,13 +299,7 @@ export function ThreadMarkdownImage(props: { | |
| ? assetImageCacheKey(props.environmentId, props.resource, assetUrl.fileRevision) | ||
| : undefined | ||
| } | ||
| sourceKey={ | ||
| props.resource._tag === "attachment" | ||
| ? `attachment:${props.resource.attachmentId}` | ||
| : props.resource._tag === "tool-output-image" | ||
| ? `tool-output:${props.resource.itemId}:${props.resource.index}` | ||
| : `workspace:${props.resource.path}` | ||
| } | ||
| sourceKey={sourceKey} | ||
| unavailable={assetUrl._tag === "Failure"} | ||
| unavailableDetail={ | ||
| assetUrl._tag === "Failure" && assetUrl.reason === "missing-file-access" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.