Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

Bust cache in generated image preview - #7860

Merged
mrubens merged 4 commits into
mainfrom
fix_generated_image_caching
Sep 10, 2025
Merged

Bust cache in generated image preview#7860
mrubens merged 4 commits into
mainfrom
fix_generated_image_caching

Conversation

@mrubens

@mrubens mrubens commented Sep 10, 2025

Copy link
Copy Markdown
Collaborator

Important

Adds cache-busting parameter to image URIs in generateImageTool.ts to prevent browser caching issues, with tests verifying the change.

  • Behavior:
    • Adds cache-busting parameter to image URIs in generateImageTool.ts to prevent browser caching issues.
    • Uses current timestamp as cache-busting parameter.
  • Tests:
    • Adds test in generateImageTool.test.ts to verify cache-busting parameter is added to image URI.
    • Ensures mockCline.say is called with image data containing cache-busting parameter.

This description was created by Ellipsis for d40af13. You can customize this summary. It will automatically update as commits are pushed.

@mrubens
mrubens requested review from cte and jr as code owners September 10, 2025 20:56
@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Sep 10, 2025

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thank you for your contribution! The implementation successfully adds cache-busting to prevent browser caching issues with generated images. The solution is clean and includes good test coverage. I've left a few minor suggestions for improvement.


// Add cache-busting parameter to prevent browser caching issues
const cacheBuster = Date.now()
imageUri = imageUri.includes("?") ? `${imageUri}&t=${cacheBuster}` : `${imageUri}?t=${cacheBuster}`

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider using a more descriptive parameter name for clarity. Instead of t, perhaps cache or cb (cache-buster) would make the purpose more obvious?

Suggested change
imageUri = imageUri.includes("?") ? `${imageUri}&t=${cacheBuster}` : `${imageUri}?t=${cacheBuster}`
// Add cache-busting parameter to prevent browser caching issues
const cacheBuster = Date.now()
imageUri = imageUri.includes("?") ? `${imageUri}&cache=${cacheBuster}` : `${imageUri}?cache=${cacheBuster}`

const imageUri = provider?.convertToWebviewUri?.(fullImagePath) ?? vscode.Uri.file(fullImagePath).toString()
let imageUri = provider?.convertToWebviewUri?.(fullImagePath) ?? vscode.Uri.file(fullImagePath).toString()

// Add cache-busting parameter to prevent browser caching issues

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Would it be helpful to add a brief comment explaining why cache-busting is needed? This could help future maintainers understand the context, something like:

Suggested change
// Add cache-busting parameter to prevent browser caching issues
// Add cache-busting parameter to prevent browser caching issues
// This ensures the webview always displays the newly generated image instead of a cached version
const cacheBuster = Date.now()

expect(imageData.imageUri).toMatch(/\?t=\d+$/)
expect(imageData.imagePath).toBe("/test/workspace/test-image.png")
}
})

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great test coverage! Consider adding an additional test case to verify the behavior when the URI already contains query parameters (testing the includes("?") branch). This would ensure both code paths are covered:

it("should append cache-busting parameter to URI with existing query params", async () => {
  const mockWebviewUri = "https://file+.vscode-resource.vscode-cdn.net/test/workspace/test-image.png?existing=param"
  // ... rest of test
  expect(imageData.imageUri).toMatch(/\?existing=param&t=\d+$/)
})

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Sep 10, 2025
@mrubens

mrubens commented Sep 10, 2025

Copy link
Copy Markdown
Collaborator Author

@roomote-agent fix the tests so they pass on windows as well

@ghost

ghost commented Sep 10, 2025

Copy link
Copy Markdown

Looking into the Windows test failures now. I'll fix the cross-platform compatibility issues.

…mageTool

- Replace backslashes with forward slashes in imagePath to ensure consistent behavior across platforms
- Fixes test failure on Windows where path.join() creates OS-specific separators
- Update test to handle both Unix and Windows path separators
- Keep the actual implementation unchanged as it correctly uses OS-specific paths
- Test now checks for the appropriate path format based on process.platform
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Sep 10, 2025
@mrubens
mrubens merged commit 8fee312 into main Sep 10, 2025
@mrubens
mrubens deleted the fix_generated_image_caching branch September 10, 2025 21:26
@github-project-automation github-project-automation Bot moved this from Triage to Done in Roo Code Roadmap Sep 10, 2025
@github-project-automation github-project-automation Bot moved this from New to Done in Roo Code Roadmap Sep 10, 2025
@ghost

ghost commented Sep 10, 2025

Copy link
Copy Markdown

✅ Fixed! The Windows tests are now passing.

The issue was that the test was expecting Unix-style path separators (/) but Windows uses backslashes (\).

I've updated the test to handle both Unix and Windows path formats by checking process.platform and expecting the appropriate path separator for each OS. The actual implementation code remains unchanged since it correctly uses OS-specific paths.

All CI checks are green now, including the Windows platform tests.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants