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] Allow TrustedHTML in dangerouslySetInnerHTML #60691

Merged

Conversation

eps1lon
Copy link
Collaborator

@eps1lon eps1lon commented Jun 6, 2022

Closes #60417

Please fill in this template.

Select one of these and delete the others:

If changing an existing definition:

/cc @lgarron

@typescript-bot
Copy link
Contributor

typescript-bot commented Jun 6, 2022

@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 you edited one package and updated the tests (👏), I can help you merge this PR once someone else signs off on it.

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 type definition owners or DT maintainers

All of the items on the list are green. To merge, you need to post a comment including the string "Ready to merge" to bring in your changes.


Diagnostic Information: What the bot saw about this PR
{
  "type": "info",
  "now": "-",
  "pr_number": 60691,
  "author": "eps1lon",
  "headCommitOid": "88ac29b42910d0988cd0450a7be0ea7a410b9a36",
  "mergeBaseOid": "595c471bd4aefa44a5d0ee49c4d73f373c319d18",
  "lastPushDate": "2022-06-06T18:08:54.000Z",
  "lastActivityDate": "2022-06-16T08:59:45.000Z",
  "maintainerBlessed": "Waiting for Code Reviews",
  "mergeOfferDate": "2022-06-15T20:50:07.000Z",
  "mergeRequestDate": "2022-06-16T08:59:45.000Z",
  "mergeRequestUser": "eps1lon",
  "hasMergeConflict": false,
  "isFirstContribution": false,
  "tooManyFiles": false,
  "hugeChange": false,
  "popularityLevel": "Critical",
  "pkgInfo": [
    {
      "name": "react",
      "kind": "edit",
      "files": [
        {
          "path": "types/react/global.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/react/index.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/react/test/index.ts",
          "kind": "test"
        },
        {
          "path": "types/react/v16/global.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/react/v16/index.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/react/v16/test/index.ts",
          "kind": "test"
        },
        {
          "path": "types/react/v17/global.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/react/v17/index.d.ts",
          "kind": "definition"
        },
        {
          "path": "types/react/v17/test/index.ts",
          "kind": "test"
        }
      ],
      "owners": [
        "johnnyreilly",
        "bbenezech",
        "pzavolinsky",
        "ericanderson",
        "DovydasNavickas",
        "theruther4d",
        "guilhermehubner",
        "ferdaber",
        "jrakotoharisoa",
        "pascaloliv",
        "hotell",
        "franklixuefei",
        "Jessidhia",
        "saranshkataria",
        "lukyth",
        "eps1lon",
        "zieka",
        "dancerphil",
        "dimitropoulos",
        "disjukr",
        "vhfmag",
        "hellatan",
        "priyanshurav"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Critical"
    }
  ],
  "reviews": [
    {
      "type": "approved",
      "reviewer": "peterblazejewicz",
      "date": "2022-06-15T20:49:24.000Z",
      "isMaintainer": true
    }
  ],
  "mainBotCommentID": 1147755504,
  "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 Jun 6, 2022
@typescript-bot
Copy link
Contributor

🔔 @johnnyreilly @bbenezech @pzavolinsky @ericanderson @DovydasNavickas @theruther4d @guilhermehubner @ferdaber @jrakotoharisoa @pascaloliv @Hotell @franklixuefei @Jessidhia @saranshkataria @lukyth @zieka @dancerphil @dimitropoulos @disjukr @vhfmag @hellatan @priyanshurav — 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 typescript-bot moved this from Needs Author Action to Waiting for Code Reviews in New Pull Request Status Board Jun 6, 2022
@DangerBotOSS
Copy link

Inspecting the JavaScript source for this package found some properties that are not in the .d.ts files.
The check for missing properties isn't always right, so take this list as advice, not a requirement.

react (unpkg)

was missing the following properties:

  1. unstable_act

Generated by 🚫 dangerJS against 88ac29b

@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Maintainer Review in New Pull Request Status Board Jun 6, 2022
@andrewbranch andrewbranch moved this from Needs Maintainer Review to Waiting for Code Reviews in New Pull Request Status Board Jun 9, 2022
Copy link
Member

@peterblazejewicz peterblazejewicz left a comment

Choose a reason for hiding this comment

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

Sebastian, thanks!
At your discretion, LGTM!

@typescript-bot typescript-bot added Maintainer Approved Self Merge This PR can now be self-merged by the PR author or an owner labels Jun 15, 2022
@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Waiting for Author to Merge in New Pull Request Status Board Jun 15, 2022
@eps1lon
Copy link
Collaborator Author

eps1lon commented Jun 16, 2022

Ready to merge

@typescript-bot typescript-bot moved this from Waiting for Author to Merge to Recently Merged in New Pull Request Status Board Jun 16, 2022
@typescript-bot typescript-bot merged commit 9c58088 into DefinitelyTyped:master Jun 16, 2022
@eps1lon eps1lon deleted the feat/react/trusted-html branch June 16, 2022 09:04
@rschaufler
Copy link

I just updated to @types/react 18.0.13 and get the following error in my app where i also use @types/trusted-types:

[ ERROR ]  TypeScript: ./node_modules/@types/trusted-types/index.d.ts:14:11
           Cannot redeclare block-scoped variable 'TrustedHTML'.

     L13:  declare global {
     L14:      const TrustedHTML: typeof lib.TrustedHTML;
     L15:      type TrustedHTML = lib.TrustedHTML;

[ ERROR ]  TypeScript: ./node_modules/@types/react/global.d.ts:157:11
           Cannot redeclare block-scoped variable 'TrustedHTML'.

    L157:  interface TrustedHTML { }

It seems to be related to the change in this PR.

@GenesisAtMac
Copy link

I just updated to @types/react 18.0.13 and get the following error in my app where i also use @types/trusted-types:

[ ERROR ]  TypeScript: ./node_modules/@types/trusted-types/index.d.ts:14:11
           Cannot redeclare block-scoped variable 'TrustedHTML'.

     L13:  declare global {
     L14:      const TrustedHTML: typeof lib.TrustedHTML;
     L15:      type TrustedHTML = lib.TrustedHTML;

[ ERROR ]  TypeScript: ./node_modules/@types/react/global.d.ts:157:11
           Cannot redeclare block-scoped variable 'TrustedHTML'.

    L157:  interface TrustedHTML { }

It seems to be related to the change in this PR.

I have the same thing with 17.0.46. I have forced 17.0.45 for the time being.

@peterblazejewicz
Copy link
Member

@eppsilon sorry, I've missed this one is global. You've folks discussed this in the linked thread (impact of global symbols from trusted-types)

@eps1lon
Copy link
Collaborator Author

eps1lon commented Jun 16, 2022

Shouldn't TrustedHTML be part of lib.dom.d.ts? Alternatively check out how lib.dom.d.ts works. Because @types/react creates a bunch of empty interfaces for DOM compat and these don't clash with lib.dom.d.ts

@peterblazejewicz
Copy link
Member

IMO 'lib.dom.d.ts' uses this combos for class/interface to allow merging, this is why it works with others, say:

interface TouchList {
    readonly length: number;
    item(index: number): Touch | null;
    [index: number]: Touch;
}

declare var TouchList: {
    prototype: TouchList;
    new(): TouchList;
};

we could ask to make a change in trusted-types to allow same (if I'm correct)

peterblazejewicz added a commit to peterblazejewicz/DefinitelyTyped that referenced this pull request Jun 16, 2022
…in `dangerouslySetInnerHTML` by @eps1lon"

This reverts commit 9c58088.
peterblazejewicz added a commit to peterblazejewicz/DefinitelyTyped that referenced this pull request Jun 16, 2022
…in `dangerouslySetInnerHTML` by @eps1lon"

This reverts commit 9c58088.

Reerts DefinitelyTyped#60691
typescript-bot pushed a commit that referenced this pull request Jun 16, 2022
@peterblazejewicz
Copy link
Member

@rschaufler @GenesisAtMac this change was reverted, sorry for the fuss. We've missed fragmentation problem with dom-like types within TS ecosystem. Thanks!

@typescript-bot typescript-bot removed this from Recently Merged in New Pull Request Status Board Jun 25, 2022
eps1lon added a commit to eps1lon/DefinitelyTyped that referenced this pull request Jul 9, 2022
….dom.d.ts et.all

This is the proper patern to augment global interfaces that are defined by the runtime.

The previous approach would break once `lib.dom.d.ts` declares these interfaces.

The previous approach also made it impossible for other libraries to use these types.
For example, DefinitelyTyped#60691 had to be reverted.
With proper module augmentation we can land DefinitelyTyped#60691 again.
@eps1lon
Copy link
Collaborator Author

eps1lon commented Jul 9, 2022

Proposed #61160 in the hopes we can reland this PR.

@eps1lon eps1lon restored the feat/react/trusted-html branch July 10, 2022 08:01
eps1lon added a commit that referenced this pull request Feb 14, 2023
#64360)

* [trusted-types] Properly augment global to prevent conflicts with lib.dom.d.ts et.all

This is the proper patern to augment global interfaces that are defined by the runtime.

The previous approach would break once `lib.dom.d.ts` declares these interfaces.

The previous approach also made it impossible for other libraries to use these types.
For example, #60691 had to be reverted.
With proper module augmentation we can land #60691 again.

* $ExpectError -> @ts-expect-error
miccehedin pushed a commit to miccehedin/DefinitelyTyped that referenced this pull request Feb 15, 2023
DefinitelyTyped#64360)

* [trusted-types] Properly augment global to prevent conflicts with lib.dom.d.ts et.all

This is the proper patern to augment global interfaces that are defined by the runtime.

The previous approach would break once `lib.dom.d.ts` declares these interfaces.

The previous approach also made it impossible for other libraries to use these types.
For example, DefinitelyTyped#60691 had to be reverted.
With proper module augmentation we can land DefinitelyTyped#60691 again.

* $ExpectError -> @ts-expect-error
typescript-bot pushed a commit that referenced this pull request Feb 20, 2023
* Add two missing mode bar buttons

* Add test with scattermapbox and new button name

* Add two more button names

* Add test for new button names

* 🤖 Merge PR #64342 feat: update @nginstack/engine definitions by @Henato

Co-authored-by: Renato <renato@innovaro.com.br>

* 🤖 Merge PR #64343 feat: update @nginstack/iquery definitions by @Henato

Co-authored-by: Renato <renato@innovaro.com.br>

* 🤖 Merge PR #64344 feat: update @nginstack/orm definitions by @Henato

Co-authored-by: Renato <renato@innovaro.com.br>

* 🤖 Merge PR #64345 feat: update @nginstack/jsunit definitions by @Henato

Co-authored-by: Renato <renato@innovaro.com.br>

* 🤖 Merge PR #64346 feat: update @nginstack/datasource definitions by @Henato

Co-authored-by: Renato <renato@innovaro.com.br>

* 🤖 Merge PR #64348 feat: update @nginstack/dev-tools definitions by @Henato

Co-authored-by: Renato <renato@innovaro.com.br>

* 🤖 Merge PR #64349 feat: update @nginstack/devops definitions by @Henato

Co-authored-by: Renato <renato@innovaro.com.br>

* 🤖 Merge PR #64240 barnard59-validate-shacl: added ValidationError export by @tpluscode

* added ValidationError export

* added test

* 🤖 Merge PR #64331 [oidc-provider] Expose as ESM module by @BendingBender

* 🤖 Merge PR #64198 [plotly.js] Add types for updatemenus by @gjulianm

* [plotly.js] Add types for updatemenus

Added types for the updatemenus property of layout. This includes two types, UpdateMenu and UpdateMenuButton

Reference: https://plotly.com/javascript/reference/layout/updatemenus/#layout-updatemenus-items-updatemenu-visible

* [plotly] run prettier

* 🤖 Merge PR #63976 update(anchor-js): version 5 bump by @peterblazejewicz

- version 5 is breaking (as per release notes)
- option for visiblity removed
- naming alinged with module documentation (options, visiblity,
  AnchorJS, etc) with aliases
- tests updated

https://github.com/bryanbraun/anchorjs/releases/tag/5.0.0

Thanks!

* Use GH_DT_MERGEBOT_TOKEN for starting action on dt-mergebot (#64357)

* [gapi.client.*] Bulk update Google API namespace (#63835)

* 🤖 Merge PR #63909 react-native-sqlite-storage: fixing typos and adding properties by @icehaunter

1. Fixed a typo in a function name
2. Fixed return type of a function
3. Added a missing property

* 🤖 Merge PR #62388 feat(geometric): Add lineRotate method to geometric module (geometric v2.4.0) by @tmcw

* feat(geometric): Add lineRotate method

* Add ScaleX and ScaleY as well

* Fix comment style

* 🤖 Merge PR #63487 fix : distribute key and restprops in react-table component's props by @Doooooring

* fix : distribute key and restprops in react-table component's props

* fix : add semicolon in react-table

* fix : add the semicolon

* [trusted-types] Properly augment global to prevent conflicts with lib… (#64360)

* [trusted-types] Properly augment global to prevent conflicts with lib.dom.d.ts et.all

This is the proper patern to augment global interfaces that are defined by the runtime.

The previous approach would break once `lib.dom.d.ts` declares these interfaces.

The previous approach also made it impossible for other libraries to use these types.
For example, #60691 had to be reverted.
With proper module augmentation we can land #60691 again.

* $ExpectError -> @ts-expect-error

* 🤖 Merge PR #63315 [ejs] adjust options.root parameter by @mshima

* [ejs] adjust root parameter

* Update index.d.ts

* [ejs] add test for root array

* Fix EJS v8 deps

---------

Co-authored-by: Piotr Błażejewicz <peterblazejewicz@users.noreply.github.com>

* 🤖 Merge PR #63879 [paypal-checkout-components] Add missing `style` and callbacks by @phylor

* Add missing `style` and callbacks to paypal-checkout-components

* Fix prettier issues

* 🤖 Merge PR #64249 meteor: Add new async methods from 2.9 by @ebroder

* 🤖 Merge PR #64363 [relay-runtime] Add cacheConfig to subscription config by @merrywhether

* 🤖 Merge PR #64337 add zhoverformat to plotly data type by @BMJHayward

Co-authored-by: Brendan Hayward <email>

* 🤖 Merge PR #64019 Fixed types for types/onfleet__node-onfleet by @YokySantiago

Fixed: property types for worker.teams, function types for task.createBatch task.autoAssign

* 🤖 Merge PR #63929 [d3-sankey] add Node.fixedValue by @simPod

* 🤖 Merge PR #63979 blessed: ListElement.setItems allows string[] by @bennbollay

* blessed: ListElement.setItems allows string[]

* Update blessed-tests.ts

* 🤖 Merge PR #63517 [react-dom] [react-native] fix incorrect typedefs for unstable_batchedUpdates by @k-yle

* 🤖 Merge PR #63877 update "wordcloud" types to align upstream by @g-plane

* update "wordcloud" types to align upstream

* update properties of "wordcloud"

* update tests of "wordcloud"

* `minFontSize` should be readonly

* update library version

* 🤖 Merge PR #63926 Update select2 Options.dropdownParent to allow additional types by @jdufresne

Per the docs at: https://select2.org/configuration/options-api
dropdownParent is allowed to be of type "jQuery selector or DOM node".

This can be further seen by the select2 code at:
https://github.com/select2/select2/blob/0a30b0b3e67843c09b0bcc4d01e65b72d9b1279f/src/js/select2/dropdown/attachBody.js#L6

* 🤖 Merge PR #63794 [@types/async] Fix return types when callback not provided by @nwalters512

* [@types/async] Fix return types when callback not provided

* Remove self as owner

* 🤖 Merge PR #63658 [ref-napi] Replace Value<T> with Pointer<T>. by @yfwz100

According to library description, a buffer is always a pointer to the underly type.

* 🤖 Merge PR #64020 fix(react-native-background-downloader): correct types for DownloadTaskState by @fivecar

It turns out that react-native-background-downloader doesn't actually export this type. Things may seem fine with doing things like `DownloadTaskState.DOWNLOADING` in your code, until you use that in a package that you also then publish yourself. At that point, you'll find the transpiled JS in your package refers to things like react_native_background_downloader_1.DownloadTaskState.DOWNLOADING, which definitely does not exist and will throw at runtime.

* 🤖 Merge PR #63968 [Nunjucks] Add `dev` argument to `ConfigureOptions` by @pezholio

There is an undocumented `dev` argument that can be sent to
`nunjucks.configure`, which allows a full error trace to the thrown

(See: mozilla/nunjucks#1430)

* 🤖 Merge PR #64073 [canvasjs] Added missing ChartOptions properties by @sampie777

Co-authored-by: S. Jansen <sa.jansen1@gmail.com>

* 🤖 Merge PR #64358 Phoenix callbacks can be async by @flupke

All callback arguments can now return T | Promise<T>, to fix annoying eslint errors like:

    Promise returned in function argument where a void return was expected. (eslint @typescript-eslint/no-misused-promises)

* 🤖 Merge PR #63921 [d3-sankey] remove unused import from tests by @simPod

---------

Co-authored-by: Henato <57230682+Henato@users.noreply.github.com>
Co-authored-by: Renato <renato@innovaro.com.br>
Co-authored-by: Tomasz Pluskiewicz <tpluscode@users.noreply.github.com>
Co-authored-by: Dimitri B <BendingBender@users.noreply.github.com>
Co-authored-by: Guillermo Julián <gjulianm@users.noreply.github.com>
Co-authored-by: Piotr Błażejewicz (Peter Blazejewicz) <peterblazejewicz@users.noreply.github.com>
Co-authored-by: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com>
Co-authored-by: Maxim Mazurok <maxim@mazurok.com>
Co-authored-by: Ilia Borovitinov <icehaunter@gmail.com>
Co-authored-by: Tom MacWright <tmcw@users.noreply.github.com>
Co-authored-by: Doooooring <106396244+Doooooring@users.noreply.github.com>
Co-authored-by: Sebastian Silbermann <sebastian.silbermann@klarna.com>
Co-authored-by: Marcelo Shima <marceloshima@gmail.com>
Co-authored-by: Serge Hänni <phylor@users.noreply.github.com>
Co-authored-by: Evan Broder <evan@ebroder.net>
Co-authored-by: Risto Keravuori <kerarist@twitch.tv>
Co-authored-by: Brendan Hayward <brendanhayward85@gmail.com>
Co-authored-by: Santiago Botero Ruiz <39206812+YokySantiago@users.noreply.github.com>
Co-authored-by: Simon Podlipsky <simon@podlipsky.net>
Co-authored-by: Benn Bollay <bb.github@magitech.org>
Co-authored-by: Kyℓe Hensel <k-yle@users.noreply.github.com>
Co-authored-by: Pig Fang <g-plane@hotmail.com>
Co-authored-by: Jon Dufresne <jon.dufresne@gmail.com>
Co-authored-by: Nathan Walters <nwalters512@gmail.com>
Co-authored-by: Wang Zhi <yfwz100@yeah.net>
Co-authored-by: Philip Su <39933441+fivecar@users.noreply.github.com>
Co-authored-by: Stuart Harrison <pezholio@gmail.com>
Co-authored-by: S. Jansen <sampie777@users.noreply.github.com>
Co-authored-by: S. Jansen <sa.jansen1@gmail.com>
Co-authored-by: Luper Rouch <luper.rouch@gmail.com>
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 Maintainer Approved Self Merge This PR can now be self-merged by the PR author or an owner
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants