Skip to content

Conversation

@adhami3310
Copy link
Member

based on #5954

@adhami3310 adhami3310 mentioned this pull request Nov 6, 2025
8 tasks
@codspeed-hq
Copy link

codspeed-hq bot commented Nov 6, 2025

CodSpeed Performance Report

Merging #5957 will not alter performance

Comparing add-mime_type-to-download (d51be18) with main (579e922)

Summary

✅ 8 untouched

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Overview

Greptile Summary

Added a mime_type parameter to the rx.download() function to allow customization of the MIME type for downloaded data. The implementation sets sensible defaults: text/plain for string data and application/octet-stream for binary data.

Key Changes

  • Removed urllib.parse import (no longer needed)
  • Added mime_type parameter to download() function signature
  • Changed string data encoding from URL encoding to base64 encoding for consistency
  • Applied mime_type to all three data type branches: str, Var, and bytes

Issues Found

  • Critical bug on line 1288: F-string used with mime_type in a Var context won't work correctly if mime_type is also a Var - needs to use string concatenation instead
  • The change from URL encoding to base64 for plain text strings is a behavioral change that could affect existing code expecting URL-encoded data URIs

Confidence Score: 2/5

  • This PR has a critical bug that will cause runtime errors when mime_type is a Var
  • Score of 2 due to a critical logic error on line 1288 where f-string interpolation won't work correctly with Var types. The mime_type needs to use dynamic string concatenation instead of f-strings. Additionally, the change from URL encoding to base64 for plain text is a breaking behavioral change that wasn't mentioned in the PR description.
  • Pay close attention to reflex/event.py line 1288 - the f-string usage with mime_type will fail when mime_type is a Var

Important Files Changed

File Analysis

Filename Score Overview
reflex/event.py 3/5 Added mime_type parameter to download() function; changed plain text encoding to base64 for all string data; potential issue with Var mime_type interpolation

Sequence Diagram

sequenceDiagram
    participant User
    participant Frontend
    participant download
    participant Browser
    
    User->>download: "Call with data or url and optional mime_type"
    
    alt URL provided
        download->>download: "Validate URL starts with slash"
        download->>download: "Infer filename from URL if needed"
        download->>Frontend: "Return EventSpec with url and filename"
    else String data provided
        download->>download: "Set mime_type to text/plain if None"
        download->>download: "Base64 encode string data"
        download->>download: "Create data URI with mime_type and base64"
        download->>Frontend: "Return EventSpec with data URI"
    else Var data provided
        download->>download: "Set mime_type to text/plain if None"
        download->>download: "Check if Var is already data URI"
        download->>download: "Use cond to handle both cases"
        download->>Frontend: "Return EventSpec with conditional data URI"
    else bytes data provided
        download->>download: "Set mime_type to octet-stream if None"
        download->>download: "Base64 encode bytes"
        download->>download: "Create data URI with mime_type"
        download->>Frontend: "Return EventSpec with data URI"
    end
    
    Frontend->>Browser: "Trigger download with URL or data URI"
    Browser->>User: "Download file with specified filename"
Loading

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@adhami3310 adhami3310 merged commit 608f71e into main Nov 6, 2025
44 of 47 checks passed
@adhami3310 adhami3310 deleted the add-mime_type-to-download branch November 6, 2025 21:47
@riebecj
Copy link
Contributor

riebecj commented Nov 7, 2025

This still doesn't fix my problem when the data is an instance of rx.Var because you're double string-quoting. The result is a downloaded file as a "My multiline\nstring" The fix for this is changing this line to f"data:{mime_type}," + data.to_string(use_json=False),

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants