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

react 19 time #4848

Merged
merged 4 commits into from
Feb 19, 2025
Merged

react 19 time #4848

merged 4 commits into from
Feb 19, 2025

Conversation

adhami3310
Copy link
Member

as downstream packages are expecting react 19 more and more, we should upgrade as well

Copy link

codspeed-hq bot commented Feb 19, 2025

CodSpeed Performance Report

Merging #4848 will not alter performance

Comparing react-19-time (10f1419) with main (deb1f4f)

Summary

✅ 12 untouched benchmarks

@adhami3310 adhami3310 closed this Feb 19, 2025
@adhami3310 adhami3310 reopened this Feb 19, 2025
@masenf
Copy link
Collaborator

masenf commented Feb 19, 2025

For future reference, the test_event_chain.py changes were required due to vercel/next.js#66210 (comment)

Specifically useEffect is not invoked twice at hydration time, even with strict mode enabled. After the app is loaded, triggering an unmount/mount, for example by navigating between pages, will trigger the useEffect twice. This is rather unfortunate, but apps should be designed to not depend on an effect running exactly some number of times -- effects "should" be idempotent, although in the case the reflex, we're actually doing IO during the effect, so it can never be technically pure.

Some lovely sample code to demonstrate the issue

import reflex as rx


class State(rx.State):
    n_mounts: int = 0
    n_unmounts: int = 0

    def on_mount(self):
        self.n_mounts += 1
        return rx.console_log(f"on_mount:{self.n_mounts}")

    def on_unmount(self):
        self.n_unmounts += 1
        return rx.console_log(f"on_unmount:{self.n_unmounts}")


def index() -> rx.Component:
    return rx.container(
        rx.vstack(
            rx.heading("Welcome to (Un)Mount!", size="9"),
            rx.text(
                "Refreshing the page increments n_mounts by 1. "
                "Navigating to Other and then back increments n_mounts by 2. "
                "Both actions increment n_mounts by 2 in react<19"
            ),
            rx.text(
                f"n_mounts:{State.n_mounts}, n_unmounts:{State.n_unmounts}",
                size="5",
                on_mount=State.on_mount,
                on_unmount=State.on_unmount,
            ),
            rx.link("Other", href="/other-page"),
        ),
        rx.logo(),
    )


def other_page():
    return rx.vstack(
        rx.heading("Other Page"),
        rx.link("Index", href="/"),
    )


app = rx.App()
app.add_page(index)
app.add_page(other_page)

Copy link
Collaborator

@masenf masenf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git-r-dun 🚢

@adhami3310 adhami3310 merged commit 6e4522c into main Feb 19, 2025
43 checks passed
@adhami3310 adhami3310 deleted the react-19-time branch February 19, 2025 22:46
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