Skip to content

React 19 API fixes - #161

Open
cknitt wants to merge 2 commits into
masterfrom
misc-fixes
Open

React 19 API fixes#161
cknitt wants to merge 2 commits into
masterfrom
misc-fixes

Conversation

@cknitt

@cknitt cknitt commented Jul 30, 2026

Copy link
Copy Markdown
Member

Summary

Correct several React 19 and React 19.2 bindings so their ReScript types match the runtime APIs.

Changes

useEffectEvent

Preserve the callback’s complete type:

external useEffectEvent: 'callback => 'callback

The previous binding only supported callbacks returning unit with at most one argument. React allows Effect Events to accept any number of arguments, return any value, and retain the original callback signature.

useFormStatus

Align the returned status with React’s pending and non-pending states:

  • Make data nullable when no form submission is active.
  • Make method nullable because it is null in the non-pending state.
  • Make action nullable when no function action is associated with the form.
  • Model action as a one-argument FormData callback instead of a useActionState reducer.
  • Remove the unused 'state type parameter that resulted from the incorrect reducer type.

resumeToPipeableStream

Correct the Node.js streaming API:

  • Return the {pipe, abort} controller directly instead of a Promise.
  • Add a dedicated pipeableStream type.
  • Add the Node streaming lifecycle options:
    • onAllReady
    • onShellReady
    • onShellError
  • Keep the shared nonce, signal, and onError options.

React returns this controller synchronously; the previous binding incorrectly described it as a promise resolving to a Node stream.

@cknitt
cknitt requested a review from fhammerschmidt July 30, 2026 14:18
@pkg-pr-new

pkg-pr-new Bot commented Jul 30, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@rescript/react@161

commit: 79e7139

@cknitt
cknitt requested a review from tsnobip July 30, 2026 14:21

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 919a40a2ba

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/ReactDOM.res Outdated
// Hooks

type formStatus<'state> = {
type formStatusAction = FormData.t => unit

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve async form action return values

When the parent form uses an async action, including the React.formAction<FormData.t> supported on line 107, useFormStatus().action refers to a function returning promise<unit> at runtime. Typing every status action as FormData.t => unit prevents callers from awaiting or handling that promise and can turn a rejected action into an unhandled rejection; this type should represent both synchronous and asynchronous form actions rather than discarding the return value.

Useful? React with 👍 / 👎.

@cknitt

cknitt commented Jul 30, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 79e7139dae

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Freddy03h

Copy link
Copy Markdown
Collaborator

I prefer keeping the function type with 1 argument, that will cover almost all the use cases of useEffectEvent and adding an unsafe binding for the edge cases : #157 (comment)

@cknitt

cknitt commented Jul 30, 2026

Copy link
Copy Markdown
Member Author

We do have the exact same issue with useCallback, and there we have:

@module("react")
external useCallback: ('f, 'deps) => 'f = "useCallback"

I think we should do the same here for consistency.

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.

3 participants