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-2810] Error: img is a self-closing tag and must neither have children nor use dangerouslySetInnerHTML. #3273

Closed
masenf opened this issue May 10, 2024 · 5 comments
Labels
enhancement Anything you want improved good first issue Good for newcomers help wanted Extra attention is needed
Milestone

Comments

@masenf
Copy link
Collaborator

masenf commented May 10, 2024

Describe the bug
When a user makes a simple mistake, and passes the image src as a child, this causes a browser error.

Instead Reflex should catch this at compile time and throw an actionable error in the terminal, or just assume what the user meant and apply the child as the src

To Reproduce

rx.image("/landing/hero.webp", alt="Reflex Logo", width="100%", height="auto"),

OOOPS, meant to write it as

rx.image(src="/landing/hero.webp", alt="Reflex Logo", width="100%", height="auto"),

Screenshots
Poor user experience 😭

image

Specifics (please complete the following information):

  • Python Version: 3.11.8
  • Reflex Version: 0.5.0a1
  • OS: macOS 14
  • Browser (Optional): Chrome

From SyncLinear.com | REF-2810

@masenf masenf added enhancement Anything you want improved good first issue Good for newcomers help wanted Extra attention is needed labels May 10, 2024
@masenf masenf changed the title Error: img is a self-closing tag and must neither have children nor use dangerouslySetInnerHTML. [REF-2810] Error: img is a self-closing tag and must neither have children nor use dangerouslySetInnerHTML. May 10, 2024
@Yummy-Yums
Copy link
Contributor

Yummy-Yums commented May 14, 2024

@masenf i tried accessing the first args assuming the user forgot to pass in the src attribute but getting an empty list. i think it stops compiling after the error is thrown . unless otherwise, it'd be best to throw an actionable error in the terminal as you suggested

Screenshot from 2024-05-14 16-15-05

@masenf
Copy link
Collaborator Author

masenf commented May 14, 2024

@Yummy-Yums i think you would want to override the create classmethod instead of __init__.

It's the call to super.__init__ that's triggering the exception, so if you call that before your logic, then the exception will be raised before you get a chance to do anything.

@Yummy-Yums
Copy link
Contributor

@masenf applying the child as src still throws a browser error but works fine in the backend , so i guess throwing the TypeError in the else block for user to handle is a better option. is this fine?

image

@masenf
Copy link
Collaborator Author

masenf commented May 14, 2024

in the else block, why not

return super().create(src=children[0], **props)

@masenf
Copy link
Collaborator Author

masenf commented May 15, 2024

Fixed via #3307

@masenf masenf closed this as completed May 15, 2024
@masenf masenf added this to the v.34 milestone May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Anything you want improved good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants