forked from cline/cline
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: optimize memory usage for image handling in webview #7556
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
83ca364
feat: optimize memory usage for image handling in webview
daniel-lxs 253deb8
fix: resolve merge conflicts with main branch
daniel-lxs 1a34943
fix: address PR review comments
daniel-lxs eccf51e
fix: address MrUbens' review comments
daniel-lxs 0365f9b
chore: remove useless comment
daniel-lxs 21d174e
chore(i18n): add image.noData to all locales to fix translation check
daniel-lxs 6f6aead
test: update ImageViewer.spec to align with i18n key and flexible pat…
daniel-lxs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,66 @@ | ||
import React from "react" | ||
import { ImageViewer } from "./ImageViewer" | ||
|
||
/** | ||
* Props for the ImageBlock component | ||
*/ | ||
interface ImageBlockProps { | ||
imageData: string | ||
/** | ||
* The webview-accessible URI for rendering the image. | ||
* This is the preferred format for new image generation tools. | ||
* Should be a URI that can be directly loaded in the webview context. | ||
*/ | ||
imageUri?: string | ||
|
||
/** | ||
* The actual file path for display purposes and file operations. | ||
* Used to show the path to the user and for opening the file in the editor. | ||
* This is typically an absolute or relative path to the image file. | ||
*/ | ||
imagePath?: string | ||
|
||
/** | ||
* Base64 data or regular URL for backward compatibility. | ||
* @deprecated Use imageUri instead for new implementations. | ||
* This is maintained for compatibility with Mermaid diagrams and legacy code. | ||
*/ | ||
imageData?: string | ||
|
||
/** | ||
* Optional path for Mermaid diagrams. | ||
* @deprecated Use imagePath instead for new implementations. | ||
* This is maintained for backward compatibility with existing Mermaid diagram rendering. | ||
*/ | ||
path?: string | ||
} | ||
|
||
export default function ImageBlock({ imageData, path }: ImageBlockProps) { | ||
export default function ImageBlock({ imageUri, imagePath, imageData, path }: ImageBlockProps) { | ||
// Determine which props to use based on what's provided | ||
let finalImageUri: string | ||
let finalImagePath: string | undefined | ||
|
||
if (imageUri) { | ||
// New format: explicit imageUri and imagePath | ||
finalImageUri = imageUri | ||
finalImagePath = imagePath | ||
} else if (imageData) { | ||
// Legacy format: use imageData as direct URI (for Mermaid diagrams) | ||
finalImageUri = imageData | ||
finalImagePath = path | ||
} else { | ||
// No valid image data provided | ||
console.error("ImageBlock: No valid image data provided") | ||
return null | ||
} | ||
|
||
return ( | ||
<div className="my-2"> | ||
<ImageViewer imageData={imageData} path={path} alt="AI Generated Image" showControls={true} /> | ||
<ImageViewer | ||
imageUri={finalImageUri} | ||
imagePath={finalImagePath} | ||
alt="AI Generated Image" | ||
showControls={true} | ||
/> | ||
</div> | ||
) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this import still needed? It appears to be unused after the refactoring: