From ca13b5aa8fed1530bccb4208eb7f0f8575607e3f Mon Sep 17 00:00:00 2001 From: David Sancho Moreno Date: Wed, 20 Nov 2024 10:10:10 +0100 Subject: [PATCH 1/6] Snapshot with lower {} --- ppx/test/lower.t/run.t | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ppx/test/lower.t/run.t b/ppx/test/lower.t/run.t index 0898fb7b4..808a6a190 100644 --- a/ppx/test/lower.t/run.t +++ b/ppx/test/lower.t/run.t @@ -94,7 +94,7 @@ ([@merlin.hide] ReactDOM.domProps)( ~children= examples - |> List.map(e => + |> List.map(e => { let Key = e.path; ReactDOM.jsxKeyed( ~key=Key, @@ -120,7 +120,7 @@ ), (), ); - ) + }) |> React.list, (), ), From 563d8af51e7968a42bc03f9899b1e5ad8784112e Mon Sep 17 00:00:00 2001 From: David Sancho Date: Wed, 20 Nov 2024 14:19:06 +0100 Subject: [PATCH 2/6] Update src/React.re MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Javier Chávarri --- src/React.re | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/React.re b/src/React.re index ba02b4222..c870c9eae 100644 --- a/src/React.re +++ b/src/React.re @@ -894,7 +894,7 @@ module Experimental = { unit => (bool, callbackAsync(callbackAsync(unit, unit), unit)) = "useTransition"; - /* https://es.react.dev/reference/react/useOptimistic */ + /* https://react.dev/reference/react/useOptimistic */ [@mel.module "react"] external useOptimistic: ('state, ('state, 'optimisticValue) => 'state) => From 9ce19ea8fe92313a54ae6c028f135f26637ca35f Mon Sep 17 00:00:00 2001 From: David Sancho Date: Wed, 20 Nov 2024 14:19:14 +0100 Subject: [PATCH 3/6] Update src/React.re MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Javier Chávarri --- src/React.re | 1 + 1 file changed, 1 insertion(+) diff --git a/src/React.re b/src/React.re index c870c9eae..92ae0199a 100644 --- a/src/React.re +++ b/src/React.re @@ -889,6 +889,7 @@ module Experimental = { /* This module is used to bind to APIs for future versions of React. There is no guarantee of backwards compatibility or stability. */ [@mel.module "react"] external usePromise: Js.Promise.t('a) => 'a = "use"; [@mel.module "react"] external useContext: Context.t('a) => 'a = "use"; + /* https://react.dev/reference/react/useTransition */ [@mel.module "react"] external useTransitionAsync: unit => (bool, callbackAsync(callbackAsync(unit, unit), unit)) = From 5636b99b453970029ca12ffd9ce500480fd70b57 Mon Sep 17 00:00:00 2001 From: David Sancho Date: Wed, 20 Nov 2024 14:19:46 +0100 Subject: [PATCH 4/6] Update src/React.re MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Javier Chávarri --- src/React.re | 1 + 1 file changed, 1 insertion(+) diff --git a/src/React.re b/src/React.re index 92ae0199a..431b7a05a 100644 --- a/src/React.re +++ b/src/React.re @@ -887,6 +887,7 @@ external useDebugValue: ('value, ~format: 'value => string=?, unit) => unit = module Experimental = { /* This module is used to bind to APIs for future versions of React. There is no guarantee of backwards compatibility or stability. */ + /* https://react.dev/reference/react/use */ [@mel.module "react"] external usePromise: Js.Promise.t('a) => 'a = "use"; [@mel.module "react"] external useContext: Context.t('a) => 'a = "use"; /* https://react.dev/reference/react/useTransition */ From cb48b76ca4c48d36b45562858366e3c52c03ff6d Mon Sep 17 00:00:00 2001 From: David Sancho Moreno Date: Mon, 25 Nov 2024 15:27:55 +0100 Subject: [PATCH 5/6] Add uri comment back on action --- src/ReactDOM.re | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ReactDOM.re b/src/ReactDOM.re index 92b7c4d6c..bedb622f2 100644 --- a/src/ReactDOM.re +++ b/src/ReactDOM.re @@ -652,7 +652,7 @@ type domProps = { [@mel.optional] acceptCharset: option(string), [@mel.optional] - action: option(string), + action: option(string), /* uri */ [@mel.optional] allowFullScreen: option(bool), [@mel.optional] From e78adccc60fa3043944bfa3bf69d0795ce5b4268 Mon Sep 17 00:00:00 2001 From: David Sancho Moreno Date: Mon, 25 Nov 2024 15:28:22 +0100 Subject: [PATCH 6/6] Add deprecations on ReactDOMTestUtils --- src/ReactDOMTestUtils.re | 276 +++++++++++++++++++++++++++++---------- 1 file changed, 209 insertions(+), 67 deletions(-) diff --git a/src/ReactDOMTestUtils.re b/src/ReactDOMTestUtils.re index 80615b4ec..0c841bf0e 100644 --- a/src/ReactDOMTestUtils.re +++ b/src/ReactDOMTestUtils.re @@ -2,76 +2,139 @@ type undefined = Js.undefined(unit); let undefined: undefined = Js.Undefined.empty; -[@mel.module "react"] +[@deprecated "use React.act instead"] [@mel.module "react"] external reactAct: ((. unit) => undefined) => unit = "act"; +[@deprecated "use React.act instead"] let act: (unit => unit) => unit = - func => { - let reactFunc = - (.) => { - func(); - undefined; - }; - reactAct(reactFunc); - }; - -[@mel.module "react"] + [@alert "-deprecated"] + ( + func => { + let reactFunc = + (.) => { + func(); + undefined; + }; + reactAct(reactFunc); + } + ); + +[@deprecated "use React.actAsync instead"] [@mel.module "react"] external reactActAsync: ((. unit) => Js.Promise.t('a)) => Js.Promise.t(unit) = "act"; -let actAsync = func => { - let reactFunc = - (.) => { - func(); - }; - reactActAsync(reactFunc); -}; +[@deprecated "use React.actAsync instead"] +let actAsync = + [@alert "-deprecated"] + ( + func => { + let reactFunc = + (.) => { + func(); + }; + reactActAsync(reactFunc); + } + ); +[@deprecated + "ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead." +] [@mel.module "react-dom/test-utils"] external isElement: 'element => bool = "isElement"; +[@deprecated + "ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead." +] [@mel.module "react-dom/test-utils"] external isElementOfType: ('element, React.component('props)) => bool = "isElementOfType"; +[@deprecated + "ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead." +] [@mel.module "react-dom/test-utils"] external isDOMComponent: 'element => bool = "isDOMComponent"; +[@deprecated + "ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead." +] [@mel.module "react-dom/test-utils"] external isCompositeComponent: 'element => bool = "isCompositeComponent"; +[@deprecated + "ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead." +] [@mel.module "react-dom/test-utils"] external isCompositeComponentWithType: ('element, React.component('props)) => bool = "isCompositeComponentWithType"; module Simulate = { - [@mel.module "react-dom/test-utils"] [@mel.scope "Simulate"] + [@deprecated + "ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead." + ] + [@mel.module "react-dom/test-utils"] + [@mel.scope "Simulate"] external click: Dom.element => unit = "click"; - [@mel.module "react-dom/test-utils"] [@mel.scope "Simulate"] + + [@deprecated + "ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead." + ] + [@mel.module "react-dom/test-utils"] + [@mel.scope "Simulate"] external clickWithEvent: (Dom.element, 'event) => unit = "click"; - [@mel.module "react-dom/test-utils"] [@mel.scope "Simulate"] + [@deprecated + "ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead." + ] + [@mel.module "react-dom/test-utils"] + [@mel.scope "Simulate"] external change: Dom.element => unit = "change"; - [@mel.module "react-dom/test-utils"] [@mel.scope "Simulate"] + + [@deprecated + "ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead." + ] + [@mel.module "react-dom/test-utils"] + [@mel.scope "Simulate"] external blur: Dom.element => unit = "blur"; - [@mel.module "react-dom/test-utils"] [@mel.scope "Simulate"] + + [@deprecated + "ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead." + ] + [@mel.module "react-dom/test-utils"] + [@mel.scope "Simulate"] external changeWithEvent: (Dom.element, 'event) => unit = "change"; - let changeWithValue = (element, value) => { - let event = { - "target": { - "value": value, - }, - }; - changeWithEvent(element, event); - }; - let changeWithChecked = (element, value) => { - let event = { - "target": { - "checked": value, - }, - }; - changeWithEvent(element, event); - }; + + [@deprecated + "ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead." + ] + let changeWithValue = + [@alert "-deprecated"] + ( + (element, value) => { + let event = { + "target": { + "value": value, + }, + }; + changeWithEvent(element, event); + } + ); + + [@deprecated + "ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead." + ] + let changeWithChecked = + [@alert "-deprecated"] + ( + (element, value) => { + let event = { + "target": { + "checked": value, + }, + }; + changeWithEvent(element, event); + } + ); [@mel.module "react-dom/test-utils"] [@mel.scope "Simulate"] external canPlay: Dom.element => unit = "canPlay"; [@mel.module "react-dom/test-utils"] [@mel.scope "Simulate"] @@ -84,65 +147,144 @@ module Simulate = { external document: Dom.document = "document"; -[@mel.return nullable] [@mel.send] +[@deprecated + "ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-webapi instead." +] +[@mel.return nullable] +[@mel.send] external querySelector: (Dom.element, string) => option(Dom.element) = "querySelector"; +[@deprecated + "ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-webapi instead." +] [@mel.send] external querySelectorAll: (Dom.element, string) => Js.Array.array_like(Dom.element) = "querySelectorAll"; -[@mel.get] external textContent: Dom.element => string = "textContent"; +[@deprecated + "ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-webapi instead." +] +[@mel.get] +external textContent: Dom.element => string = "textContent"; -[@mel.return nullable] [@mel.get] +[@deprecated + "ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-webapi instead." +] +[@mel.return nullable] +[@mel.get] external body: Dom.document => option(Dom.element) = "body"; +[@deprecated + "ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-webapi instead." +] [@mel.send] external createElement: (Dom.document, string) => Dom.element = "createElement"; -[@mel.send] external remove: Dom.element => unit = "remove"; + +[@deprecated + "ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-webapi instead." +] +[@mel.send] +external remove: Dom.element => unit = "remove"; + +[@deprecated + "ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-webapi instead." +] [@mel.send] external appendChild: (Dom.element, Dom.element) => Dom.element = "appendChild"; -let querySelectorAll = (element, string) => { - Js.Array.from(querySelectorAll(element, string)); -}; +[@deprecated + "ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-webapi instead." +] +let querySelectorAll = + [@alert "-deprecated"] + ( + (element, string) => { + Js.Array.from(querySelectorAll(element, string)); + } + ); module DOM = { - [@mel.return nullable] [@mel.get] + [@deprecated + "ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-webapi instead." + ] + [@mel.return nullable] + [@mel.get] external value: Dom.element => option(string) = "value"; - let findBySelector = (element, selector) => - querySelector(element, selector); + [@deprecated + "ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-webapi instead." + ] + let findBySelector = + [@alert "-deprecated"] + ((element, selector) => querySelector(element, selector)); + [@deprecated + "ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-webapi instead." + ] let findByAllSelector = (element, selector) => querySelectorAll(element, selector); - let findBySelectorAndTextContent = (element, selector, content) => - querySelectorAll(element, selector) - |> Array.find_opt(node => node->textContent === content); + [@deprecated + "ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-webapi instead." + ] + let findBySelectorAndTextContent = + [@alert "-deprecated"] + ( + (element, selector, content) => + querySelectorAll(element, selector) + |> Array.find_opt(node => node->textContent === content) + ); - let findBySelectorAndPartialTextContent = (element, selector, content) => - querySelectorAll(element, selector) - |> Array.find_opt(node => - Js.String.includes(~search=content, node->textContent) - ); + [@deprecated + "ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-webapi instead." + ] + let findBySelectorAndPartialTextContent = + [@alert "-deprecated"] + ( + (element, selector, content) => + querySelectorAll(element, selector) + |> Array.find_opt(node => + Js.String.includes(~search=content, node->textContent) + ) + ); }; -let prepareContainer = (container: ref(option(Dom.element)), ()) => { - let containerElement = document->createElement("div"); - let _: option(_) = - Option.map(body => body->appendChild(containerElement), document->body); - container := Some(containerElement); -}; +[@deprecated + "ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead." +] +let prepareContainer = + [@alert "-deprecated"] + ( + (container: ref(option(Dom.element)), ()) => { + let containerElement = document->createElement("div"); + let _: option(_) = + Option.map( + body => body->appendChild(containerElement), + document->body, + ); + container := Some(containerElement); + } + ); -let cleanupContainer = (container: ref(option(Dom.element)), ()) => { - let _: option(_) = Option.map(remove, container^); - container := None; -}; +[@deprecated + "ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead." +] +let cleanupContainer = + [@alert "-deprecated"] + ( + (container: ref(option(Dom.element)), ()) => { + let _: option(_) = Option.map(remove, container^); + container := None; + } + ); +[@deprecated + "ReactDOMTestUtils is deprecated, and will be removed in next version. Please use melange-testing-library instead." +] let getContainer = container => { container.contents->Option.get; };