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

PyScript components become unresponsive on exceptions #1276

Open
Archmonger opened this issue Feb 12, 2025 · 0 comments
Open

PyScript components become unresponsive on exceptions #1276

Archmonger opened this issue Feb 12, 2025 · 0 comments
Labels
priority-2-moderate Should be resolved on a reasonable timeline.

Comments

@Archmonger
Copy link
Contributor

Current Situation

If an exception is thrown in the component body of a PyScript component, the component's become unresponsive. This can be demonstrated by using the following pyscript component

from reactpy import component, hooks, html

@component
def root():
    count, set_count = hooks.use_state(0)

    def increment(event):
        set_count(count + 1)

    if count == 5:
        raise ValueError("This error both breaks this component's rendering stack, and does not hide the component.")

    return html.div(
        html.button({"onClick": increment}, "Increment"),
        html.p(f"Count: {count}"),
    )

This is strange since layout.py defines that components should hide themselves when exceptions occur, and that's clearly not happening.

Something notable is that this issue only occurs if the exception occurs in the root component. The expected behavior will occur if the exception happens in any child components. For example...

@component
def root():
    return html.fragment(
        counter(),
        counter(),
    )


@component
def counter():
    count, set_count = hooks.use_state(0)

    def increment(event):
        set_count(count + 1)

    if count == 5:
        raise ValueError("This is an error 2")

    return html.div(
        html.button({"onClick": increment}, "Increment"),
        html.p(f"PyScript Count: {count}"),
    )

Proposed Actions

Figure out why this behavior exists. Perhaps it also exists in server-side components and we just haven't noticed until now?

@Archmonger Archmonger added the priority-2-moderate Should be resolved on a reasonable timeline. label Feb 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority-2-moderate Should be resolved on a reasonable timeline.
Projects
None yet
Development

No branches or pull requests

1 participant