reactpy icon indicating copy to clipboard operation
reactpy copied to clipboard

report better error for attrs that cannot be serialized

Open rmorshea opened this issue 2 years ago • 2 comments
trafficstars

Issues

closes: #930

Summary

In reactpy.core.vdom.vdom check if attributes are JSON serializable when in debug mode.

Also misc changes to config options to make this easier in particular ability to specify options as parents.

Checklist

  • [ ] Tests have been included for all bug fixes or added functionality.
  • [ ] The changelog.rst has been updated with any significant changes.

rmorshea avatar Jun 06 '23 06:06 rmorshea

We might also want to validate event handlers too. Need to ensure they're either coroutines or callable.

Archmonger avatar Jun 07 '23 06:06 Archmonger

We might also want to validate event handlers too.

Event handlers are already extracted from attributes based on whether they are callable or not.

rmorshea avatar Jun 07 '23 19:06 rmorshea

We might also want to validate event handlers too.

Event handlers are already extracted from attributes based on whether they are callable or not.

I currently don't see any warnings if I put in a string as an event handler.

from reactpy import component, html, run


@component
def test():
    return html.div({"on_click": "do nothing"}, "Hello World")


run(test)

Archmonger avatar Jun 15 '23 04:06 Archmonger

Also I don't see how this PR resolves #437

Archmonger avatar Jun 15 '23 04:06 Archmonger

I currently don't see any warnings if I put in a string as an event handler.

This is strictly about ensuring that attributes are JSON serializable. Know what values are allowed for each attribute on each HTML element would need to be done in a follow-up PR.

rmorshea avatar Jun 15 '23 04:06 rmorshea

Also I don't see how this PR resolves https://github.com/reactive-python/reactpy/issues/437

In debug mode, users will get an error if they attempt to pass non-JSON-serializable props to a JS components. They'd get that error without debug mode too, but in debug mode you get a more helpful one.

rmorshea avatar Jun 15 '23 04:06 rmorshea