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

useFormState: Emit comment to mark whether state matches #27307

Merged
merged 1 commit into from
Sep 7, 2023

Commits on Sep 7, 2023

  1. useFormState: Emit comment to mark whether state matches

    A planned feature of useFormState is that if page load is the result of an
    MPA-style form submission — i.e. a form was submitted before it was hydrated,
    using Server Actions — the state should transfer to the next page.
    
    I haven't implemented that part yet, but as a prerequisite, we need some way for
    Fizz to indicate whether a useFormState hook was rendered using the "postback"
    state. That way we can do all state matching logic on the server without
    having to replicate it on the client, too.
    
    The approach here is to emit a comment node for each useFormState hook. We use
    one of two comment types: `<!--F-->` for a normal useFormState hook, and
    `<!--F!-->` for a hook that was rendered using the postback state. React will
    read these markers during hydration. This is similar to how we encode
    Suspense boundaries.
    
    Again, the actual matching algorithm is not yet implemented — for now, the
    "not matching" marker is always emitted.
    
    We can optimize this further by not emitting any markers for a render that is
    not the result of a form postback, which I'll do in subsequent PRs.
    acdlite committed Sep 7, 2023
    Configuration menu
    Copy the full SHA
    18da28b View commit details
    Browse the repository at this point in the history