Skip to content

PyScript components become unresponsive on exceptions #1276

Closed

Description

@Archmonger

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 this behavior also exists in server-side components and we just haven't noticed until now?

Activity

  1. Prachi-Gupta2808 commented on Jul 1, 2026

    @Prachi-Gupta2808
    Contributor

    @Archmonger can I work on this? Please assign me this or give me a green flag that no one else is working on this. also it would be great if you can highlight the files/folders which are involved in this bug and might be needed under my scope.

  2. Archmonger commented on Jul 1, 2026

    @Archmonger
    ContributorAuthor
  3. Prachi-Gupta2808 commented on Jul 3, 2026

    @Prachi-Gupta2808
    Contributor

    @Archmonger I have raised a PR for this, please review this when possible.
    Thanks alot.

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

    priority-2-moderateShould be resolved on a reasonable timeline.

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions