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

[REF-3185] Expected unicode escape when rendering rx.selected_files in rx.text #3555

Closed
maximvlah opened this issue Jun 25, 2024 · 0 comments
Labels
linear Created by Linear-GitHub Sync Reflex > Open source core OSS Created by Linear-GitHub Sync
Milestone

Comments

@maximvlah
Copy link
Contributor

maximvlah commented Jun 25, 2024

Description

We get "Expected unicode escape" error when rendering rx.selected_files within rx.text

Reproduce

import reflex as rx

upload_id="upload_id1"

def index():

    return rx.vstack(
        rx.upload(
            rx.vstack(
                rx.button("Select File"),
                rx.text("Drag and drop files here or click to select files"),
            ),
            id=upload_id,
            directory=False,
        ),
        rx.box(
            rx.foreach(
                rx.selected_files(upload_id),
                rx.text,
            ),
        ),

        # This breaks the code
        rx.text(f"Selected Files: {rx.selected_files(upload_id).length()}"), 
         # This breaks too
        rx.text(f"Selected Files: {rx.selected_files(upload_id)}"),
    )

app = rx.App()

app.add_page(index)
./pages/index.js
Error: 
  x Expected unicode escape
    ,-[/home/mvlah/dev/senbax/reflex/reflex-maxim/reflex/examples/.web/pages/index.js:17:1]
 17 | 
 18 |   return (
 19 |     <RadixThemesText as={`p`}>
 20 |   {`Selected Files: ${(filesById[\`upload_id1\`] ? filesById[\`upload_id1\`].map((f) => (f.path || f.name)) : []).length}`}
    :                                  ^
 21 | </RadixThemesText>
 22 | 
 23 |   )
    `----

Caused by:
    Syntax Error

#3449 (review) seems to have broken it as before it was like below and worked fine. However it did not allow passing upload ids with special characters:

@CallableVar
def selected_files(id_: str = DEFAULT_UPLOAD_ID) -> BaseVar:
    """Get the list of selected files.

    Args:
        id_: The id of the upload to get the selected files for.

    Returns:
        A var referencing the list of selected file paths.
    """
    return BaseVar(
        _var_name=f"(filesById.{id_} ? filesById.{id_}.map((f) => (f.path || f.name)) : [])",
        _var_type=List[str],
        _var_data=upload_files_context_var_data,
    )

Related issue: #3045

REF-3185

@maximvlah maximvlah added the bug Something isn't working label Jun 25, 2024
@maximvlah maximvlah changed the title Expected unicode escape when rendering rx.selected_files in rx.text Expected unicode escape when rendering rx.selected_files in rx.text Jun 25, 2024
@Lendemor Lendemor added the linear Created by Linear-GitHub Sync label Jun 25, 2024
@Lendemor Lendemor changed the title Expected unicode escape when rendering rx.selected_files in rx.text [REF-3185] Expected unicode escape when rendering rx.selected_files in rx.text Jun 25, 2024
@Lendemor Lendemor modified the milestones: Open Source Bugs, v.40 Jun 25, 2024
@Lendemor Lendemor added Reflex > Open source core OSS Created by Linear-GitHub Sync bug Something isn't working and removed bug Something isn't working labels Sep 3, 2024
@Lendemor Lendemor added bug Something isn't working and removed bug Something isn't working labels Sep 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linear Created by Linear-GitHub Sync Reflex > Open source core OSS Created by Linear-GitHub Sync
Projects
None yet
Development

No branches or pull requests

2 participants