Skip to content

rx.toast.dismiss breaks for IDs containing quotes or newlines #8017

Backlog

Description

@harsh21234i

Describe the bug

rx.toast.dismiss(id: str) inserts the ID directly inside a single-quoted JavaScript string without escaping it. Valid IDs containing an apostrophe or newline produce invalid JavaScript, so the generated event cannot run (and can make the frontend script fail to parse).

To Reproduce

import reflex as rx


def index():
    return rx.button("Dismiss", on_click=rx.toast.dismiss("toast's-id"))


app = rx.App()
app.add_page(index)

The generated expression is:

refs['__toast'].dismiss('toast's-id')

Node rejects this with SyntaxError: missing ) after argument list. A newline in the ID also becomes a literal newline inside the quoted string and fails parsing.

Expected behavior

The string ID should be serialized as a valid JavaScript string literal so any supported ID can be passed to rx.toast.dismiss.

Specifics

  • Verified against current upstream main (6f5c39cac).
  • The affected code is packages/reflex-components-sonner/src/reflex_components_sonner/toast.py, in Toaster.toast_dismiss.

Additional context

This concerns only the Python str ID branch; the Var[str] branch already emits a variable expression. Existing toast style-prop issues concern different props and do not cover dismissal ID escaping.

Activity

  1. linear-code commented on Nov 26, 2026

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions