Skip to content

[react-dom] Add support for createRoot(document) in Canary and Experimental release channels#68892

Merged
eps1lon merged 2 commits into
DefinitelyTyped:masterfrom
eps1lon:feat/react-dom/creatre-root-document
Mar 5, 2024
Merged

[react-dom] Add support for createRoot(document) in Canary and Experimental release channels#68892
eps1lon merged 2 commits into
DefinitelyTyped:masterfrom
eps1lon:feat/react-dom/creatre-root-document

Conversation

@eps1lon

@eps1lon eps1lon commented Mar 4, 2024

Copy link
Copy Markdown
Collaborator

Types for react/react#25426


/**
* Replaces `ReactDOM.render` when the `.render` method is called and enables Concurrent Mode.
* createRoot lets you create a root to display React components inside a browser DOM node.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Just copy&paste from reference docs. Didn't add some to the one for document in Canary since we're missing docs for that.

@eps1lon eps1lon changed the title [react-dom] Add support for createRoot(document) in Canary and Experimental release channels [react-dom] Add support for createRoot(document) in Canary and Experimental release channels Mar 4, 2024
Comment thread types/react-dom/canary.d.ts Outdated
formState?: ReactFormState | null;
}

function createRoot(container: Document, options?: RootOptions): Root;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

not sure how these things layer together. Does this essentially support Document | Element when using canary and experimental builds?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah good call. Overloads are annoying anyway so I go with the same pattern we use in react types to augment unions

Comment on lines +41 to +46
export type Container =
| Element
| DocumentFragment
| DO_NOT_USE_OR_YOU_WILL_BE_FIRED_EXPERIMENTAL_CREATE_ROOT_CONTAINERS[
keyof DO_NOT_USE_OR_YOU_WILL_BE_FIRED_EXPERIMENTAL_CREATE_ROOT_CONTAINERS
];

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

DO_NOT_USE_OR_YOU_WILL_BE_FIRED_EXPERIMENTAL_CREATE_ROOT_CONTAINERS will not leak into error messages or type hints. TypeScript will resolve T[keyof T]:

Screenshot 2024-03-04 at 23 27 45

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

whoa that's clever

@eps1lon eps1lon marked this pull request as ready for review March 4, 2024 22:39
@eps1lon eps1lon requested a review from Jessidhia as a code owner March 4, 2024 22:39
@typescript-bot

typescript-bot commented Mar 4, 2024

Copy link
Copy Markdown
Contributor

@eps1lon Thank you for submitting this PR!

This is a live comment which I will keep updated.

1 package in this PR

Code Reviews

Because this is a widely-used package, a DT maintainer will need to review it before it can be merged.

You can test the changes of this PR in the Playground.

Status

  • ✅ No merge conflicts
  • ✅ Continuous integration tests have passed
  • 🕐 Most recent commit is approved by a DT maintainer

Once every item on this list is checked, I'll ask you for permission to merge and publish the changes.


Diagnostic Information: What the bot saw about this PR
{
  "type": "info",
  "now": "-",
  "pr_number": 68892,
  "author": "eps1lon",
  "headCommitOid": "affa97443421ff6efb2c6795a3f66239972e0480",
  "mergeBaseOid": "6051dcae005e4bc3cb54c384deb2b8487b733688",
  "lastPushDate": "2024-03-04T22:06:49.000Z",
  "lastActivityDate": "2024-03-05T15:43:26.000Z",
  "hasMergeConflict": false,
  "isFirstContribution": false,
  "tooManyFiles": false,
  "hugeChange": false,
  "popularityLevel": "Critical",
  "pkgInfo": [
    {
      "name": "react-dom",
      "kind": "edit",
      "files": [
        {
          "path": "types/react-dom/canary.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/react-dom/client.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/react-dom/test/canary-tests.tsx",
          "kind": "test"
        },
        {
          "path": "types/react-dom/test/react-dom-tests.tsx",
          "kind": "test"
        }
      ],
      "owners": [
        "MartynasZilinskas",
        "theruther4d",
        "Jessidhia",
        "eps1lon"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Critical"
    }
  ],
  "reviews": [
    {
      "type": "approved",
      "reviewer": "gnoff",
      "date": "2024-03-05T15:43:26.000Z",
      "isMaintainer": false
    }
  ],
  "mainBotCommentID": 1977592954,
  "ciResult": "pass"
}

@typescript-bot typescript-bot added Critical package Author is Owner The author of this PR is a listed owner of the package. labels Mar 4, 2024
@typescript-bot

Copy link
Copy Markdown
Contributor

🔔 @MartynasZilinskas @theruther4d @Jessidhia — please review this PR in the next few days. Be sure to explicitly select Approve or Request Changes in the GitHub UI so I know what's going on.

@typescript-bot

Copy link
Copy Markdown
Contributor

@gnoff Thank you for reviewing this PR! The author has pushed new commits since your last review. Could you take another look and submit a fresh review?

@typescript-bot typescript-bot added the Other Approved This PR was reviewed and signed-off by a community member. label Mar 5, 2024
@eps1lon eps1lon merged commit a0cdcf3 into DefinitelyTyped:master Mar 5, 2024
@eps1lon eps1lon deleted the feat/react-dom/creatre-root-document branch March 5, 2024 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author is Owner The author of this PR is a listed owner of the package. Critical package Other Approved This PR was reviewed and signed-off by a community member.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants