Skip to content

fix: use rx.Var.create to get a str var#1684

Merged
carlosabadia merged 1 commit intoreflex-dev:mainfrom
macmoritz:fix-local-packages-example-rx-var
Nov 5, 2025
Merged

fix: use rx.Var.create to get a str var#1684
carlosabadia merged 1 commit intoreflex-dev:mainfrom
macmoritz:fix-local-packages-example-rx-var

Conversation

@macmoritz
Copy link
Copy Markdown
Contributor

When using rx.Var("Hello") this is rendered to Hello without quotes, so no string. Therefor the frontend can not handle this.
With the help of @benedikt-bartscher this was quickly solved by using rx.Var.create("Hello").

There are more occurences, which might be failing too:

>>> ag "rx.Var\(\""
pcweb/components/hosting_banner.py
40:            rx.Var("t").to(str), "-", ""

pcweb/pages/hosting_countdown/timer.py
8:            rx.Var("t").to(str), "-", ""

docs/api-reference/var_system.md
49:rx.Var("2", _var_type=int).guess_type() # NumberVar

docs/enterprise/react_flow/nodes.md
243:                    ("node",), node_stroke_color(rx.Var("node").to(Node))
246:                    ("node",), node_color(rx.Var("node").to(Node))

Copy link
Copy Markdown
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

Fixed a documentation example that incorrectly used rx.Var("World") to set a default string value for a component field. Changed to rx.Var.create("World") to ensure proper string quoting in the generated frontend code.

Key Changes:

  • Updated docs/wrapping-react/local-packages.md:74 from rx.Var("World") to rx.Var.create("World")
  • This aligns with the established pattern used in other components (pcweb/components/number_flow.py, pcweb/components/marquee.py)

Related Concerns:
The PR description mentions additional occurrences of rx.Var("...") in other files that may have similar issues:

  • pcweb/components/hosting_banner.py:40 - uses rx.Var("t").to(str) in a function context
  • pcweb/pages/hosting_countdown/timer.py:8 - uses rx.Var("t").to(str) in a function context
  • docs/api-reference/var_system.md:49 - uses rx.Var("2", _var_type=int) as a documentation example for raw JavaScript strings
  • docs/enterprise/react_flow/nodes.md:243,246 - uses rx.Var("node").to(Node) in function contexts

These other occurrences appear to be used in different contexts (function arguments for ArgsFunctionOperation.create) where rx.Var() might be intentionally creating raw JavaScript variable references rather than string literals. However, they warrant separate investigation to confirm they work as intended.

Confidence Score: 5/5

  • This PR is safe to merge - it fixes a legitimate bug in documentation example code
  • The change correctly fixes a documentation example by following the established pattern used throughout the codebase for setting default string values on Var fields. The fix is minimal (one line), well-understood, and aligns with existing best practices in the codebase.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
docs/wrapping-react/local-packages.md 5/5 Changed rx.Var("World") to rx.Var.create("World") to fix frontend rendering issue where strings were not properly quoted

Sequence Diagram

sequenceDiagram
    participant Dev as Developer
    participant Comp as Hello Component
    participant Reflex as Reflex Framework
    participant Frontend as Frontend/Browser

    Dev->>Comp: Define name field with default value
    Note over Comp: Before: rx.Var("World")<br/>After: rx.Var.create("World")
    
    Comp->>Reflex: Register component with Var field
    
    alt Using rx.Var("World") [Before Fix]
        Reflex->>Frontend: Renders as: World (no quotes)
        Frontend->>Frontend: Parse error: expected string
        Note over Frontend: Frontend cannot handle<br/>unquoted literal
    end
    
    alt Using rx.Var.create("World") [After Fix]
        Reflex->>Frontend: Renders as: "World" (quoted string)
        Frontend->>Frontend: Successfully parses string value
        Note over Frontend: Frontend correctly interprets<br/>quoted string literal
    end
Loading

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@carlosabadia carlosabadia merged commit 9d97a3c into reflex-dev:main Nov 5, 2025
6 of 10 checks passed
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.

2 participants