@wordpress/element 6.46.0 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,24 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 8.0.0 (2026-06-04)
6
+
7
+ ### Breaking Changes
8
+
9
+ - Revert React back to v18 [#78940](https://github.com/WordPress/gutenberg/pull/78940).
10
+
11
+ ## 7.0.0 (2026-05-27)
12
+
13
+ ### Breaking Changes
14
+
15
+ - Updated dependencies to React 19.2.4 ([#61521](https://github.com/WordPress/gutenberg/pull/61521)).
16
+ - Removed the `render`, `hydrate` and `unmountComponentAtNode` exports that have been deprecated since WordPress 6.2 after upgrade to React 18 ([#61521](https://github.com/WordPress/gutenberg/pull/61521)).
17
+
18
+ ### New Features
19
+
20
+ - Added new `react` exports: `Activity`, `use`, `useActionState`, `useEffectEvent`, and `useOptimistic` ([#61521](https://github.com/WordPress/gutenberg/pull/61521)).
21
+ - Added new `react-dom` exports: `useFormStatus`, `preconnect`, `prefetchDNS`, `preinit`, `preinitModule`, `preload`, and `preloadModule` ([#61521](https://github.com/WordPress/gutenberg/pull/61521)).
22
+
5
23
  ## 6.46.0 (2026-05-14)
6
24
 
7
25
  ## 6.45.0 (2026-04-29)
package/README.md CHANGED
@@ -122,12 +122,7 @@ Creates a portal into which a component can be rendered.
122
122
 
123
123
  _Related_
124
124
 
125
- - <https://github.com/facebook/react/issues/10309#issuecomment-318433235>
126
-
127
- _Parameters_
128
-
129
- - _child_ `React.ReactElement`: Any renderable child, such as an element, string, or fragment.
130
- - _container_ `HTMLElement`: DOM node into which element should be rendered.
125
+ - <https://react.dev/reference/react-dom/createPortal>
131
126
 
132
127
  ### createRef
133
128
 
@@ -161,9 +156,9 @@ _Parameters_
161
156
 
162
157
  Forces React to flush any updates inside the provided callback synchronously.
163
158
 
164
- _Parameters_
159
+ _Related_
165
160
 
166
- - _callback_ `Function`: Callback to run synchronously.
161
+ - <https://react.dev/reference/react-dom/flushSync>
167
162
 
168
163
  ### forwardRef
169
164
 
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts"],
4
- "sourcesContent": ["export { default as createInterpolateElement } from './create-interpolate-element';\nexport * from './react';\nexport * from './react-platform';\nexport * from './utils';\nexport { default as Platform } from './platform';\nexport { default as renderToString } from './serialize';\nexport { default as RawHTML } from './raw-html';\n"],
4
+ "sourcesContent": ["export { default as createInterpolateElement } from './create-interpolate-element';\nexport * from './react';\nexport * from './react-platform';\nexport * from './utils';\nexport { default as Platform } from './platform';\nexport { default as renderToString } from './serialize';\nexport { default as RawHTML } from './raw-html';\n// export {\n// \tfindDOMNode,\n// \trender,\n// \thydrate,\n// \tunmountComponentAtNode,\n// } from './react-polyfill';\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wCAAoD;AACpD,0BAAc,wBADd;AAEA,0BAAc,iCAFd;AAGA,0BAAc,wBAHd;AAIA,sBAAoC;AACpC,uBAA0C;AAC1C,sBAAmC;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/react-platform.ts"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport {\n\tcreatePortal,\n\tfindDOMNode,\n\tflushSync,\n\t/* eslint-disable react/no-deprecated */\n\trender,\n\thydrate,\n\tunmountComponentAtNode,\n\t/* eslint-enable react/no-deprecated */\n} from 'react-dom';\nimport { createRoot, hydrateRoot } from 'react-dom/client';\n\n/**\n * Creates a portal into which a component can be rendered.\n *\n * @see https://github.com/facebook/react/issues/10309#issuecomment-318433235\n *\n * @param {React.ReactElement} child Any renderable child, such as an element,\n * string, or fragment.\n * @param {HTMLElement} container DOM node into which element should be rendered.\n */\nexport { createPortal };\n\n/**\n * Finds the dom node of a React component.\n *\n * @param {React.ComponentType} component Component's instance.\n */\nexport { findDOMNode };\n\n/**\n * Forces React to flush any updates inside the provided callback synchronously.\n *\n * @param {Function} callback Callback to run synchronously.\n */\nexport { flushSync };\n\n/**\n * Renders a given element into the target DOM node.\n *\n * @deprecated since WordPress 6.2.0. Use `createRoot` instead.\n * @see https://react.dev/reference/react-dom/render\n */\nexport { render };\n\n/**\n * Hydrates a given element into the target DOM node.\n *\n * @deprecated since WordPress 6.2.0. Use `hydrateRoot` instead.\n * @see https://react.dev/reference/react-dom/hydrate\n */\nexport { hydrate };\n\n/**\n * Creates a new React root for the target DOM node.\n *\n * @since 6.2.0 Introduced in WordPress core.\n * @see https://react.dev/reference/react-dom/client/createRoot\n */\nexport { createRoot };\n\n/**\n * Creates a new React root for the target DOM node and hydrates it with a pre-generated markup.\n *\n * @since 6.2.0 Introduced in WordPress core.\n * @see https://react.dev/reference/react-dom/client/hydrateRoot\n */\nexport { hydrateRoot };\n\n/**\n * Removes any mounted element from the target DOM node.\n *\n * @deprecated since WordPress 6.2.0. Use `root.unmount()` instead.\n * @see https://react.dev/reference/react-dom/unmountComponentAtNode\n */\nexport { unmountComponentAtNode };\n"],
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport {\n\tcreatePortal,\n\tfindDOMNode,\n\tflushSync,\n\t/* eslint-disable react/no-deprecated */\n\trender,\n\thydrate,\n\tunmountComponentAtNode,\n\t/* eslint-enable react/no-deprecated */\n} from 'react-dom';\nimport { createRoot, hydrateRoot } from 'react-dom/client';\n\n/**\n * Creates a portal into which a component can be rendered.\n *\n * @see https://react.dev/reference/react-dom/createPortal\n */\nexport { createPortal };\n\n/**\n * Finds the dom node of a React component.\n *\n * @param {React.ComponentType} component Component's instance.\n */\nexport { findDOMNode };\n\n/**\n * Forces React to flush any updates inside the provided callback synchronously.\n *\n * @see https://react.dev/reference/react-dom/flushSync\n */\nexport { flushSync };\n\n/**\n * Renders a given element into the target DOM node.\n *\n * @deprecated since WordPress 6.2.0. Use `createRoot` instead.\n * @see https://react.dev/reference/react-dom/render\n */\nexport { render };\n\n/**\n * Hydrates a given element into the target DOM node.\n *\n * @deprecated since WordPress 6.2.0. Use `hydrateRoot` instead.\n * @see https://react.dev/reference/react-dom/hydrate\n */\nexport { hydrate };\n\n/**\n * Creates a new React root for the target DOM node.\n *\n * @since 6.2.0 Introduced in WordPress core.\n * @see https://react.dev/reference/react-dom/client/createRoot\n */\nexport { createRoot };\n\n/**\n * Creates a new React root for the target DOM node and hydrates it with a pre-generated markup.\n *\n * @since 6.2.0 Introduced in WordPress core.\n * @see https://react.dev/reference/react-dom/client/hydrateRoot\n */\nexport { hydrateRoot };\n\n/**\n * Removes any mounted element from the target DOM node.\n *\n * @deprecated since WordPress 6.2.0. Use `root.unmount()` instead.\n * @see https://react.dev/reference/react-dom/unmountComponentAtNode\n */\nexport { unmountComponentAtNode };\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBASO;AACP,oBAAwC;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,132 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // packages/element/src/react-polyfill-base.ts
21
+ var react_polyfill_base_exports = {};
22
+ __export(react_polyfill_base_exports, {
23
+ findDOMNode: () => findDOMNode,
24
+ hydrate: () => hydrate,
25
+ render: () => render,
26
+ unmountComponentAtNode: () => unmountComponentAtNode
27
+ });
28
+ module.exports = __toCommonJS(react_polyfill_base_exports);
29
+ var import_react_dom = require("react-dom");
30
+ var import_client = require("react-dom/client");
31
+ var internalsKey = "_reactInternals";
32
+ var HostComponent = 5;
33
+ var HostText = 6;
34
+ function findCurrentFiber(fiber) {
35
+ if (!fiber.alternate) {
36
+ return fiber;
37
+ }
38
+ let node = fiber;
39
+ while (node.return) {
40
+ node = node.return;
41
+ }
42
+ if (node.stateNode.current === node) {
43
+ return fiber;
44
+ }
45
+ return fiber.alternate;
46
+ }
47
+ function findHostFiber(fiber) {
48
+ const current = findCurrentFiber(fiber);
49
+ if (!current) {
50
+ return null;
51
+ }
52
+ return findHostFiberImpl(current);
53
+ }
54
+ function findHostFiberImpl(fiber) {
55
+ if (fiber.tag === HostComponent || fiber.tag === HostText) {
56
+ return fiber;
57
+ }
58
+ let child = fiber.child;
59
+ while (child) {
60
+ const hostFiber = findHostFiberImpl(child);
61
+ if (hostFiber) {
62
+ return hostFiber;
63
+ }
64
+ child = child.sibling;
65
+ }
66
+ return null;
67
+ }
68
+ function findDOMNode(instance) {
69
+ if (instance === null || instance === void 0) {
70
+ return null;
71
+ }
72
+ if (instance.nodeType !== void 0) {
73
+ return instance;
74
+ }
75
+ const fiber = instance[internalsKey];
76
+ if (fiber === void 0) {
77
+ if (typeof instance.render === "function") {
78
+ throw new Error("Unable to find node on an unmounted component.");
79
+ }
80
+ const keys = Object.keys(instance).join(",");
81
+ throw new Error(
82
+ `Argument appears to not be a ReactComponent. Keys: ${keys}`
83
+ );
84
+ }
85
+ const hostFiber = findHostFiber(fiber);
86
+ return hostFiber?.stateNode ?? null;
87
+ }
88
+ var roots = /* @__PURE__ */ new WeakMap();
89
+ function render(element, container, callback) {
90
+ let root = roots.get(container);
91
+ if (!root) {
92
+ root = (0, import_client.createRoot)(container);
93
+ roots.set(container, root);
94
+ }
95
+ (0, import_react_dom.flushSync)(() => {
96
+ root.render(element);
97
+ });
98
+ if (typeof callback === "function") {
99
+ callback();
100
+ }
101
+ }
102
+ function hydrate(element, container, callback) {
103
+ let root = roots.get(container);
104
+ if (!root) {
105
+ root = (0, import_client.hydrateRoot)(container, element);
106
+ roots.set(container, root);
107
+ } else {
108
+ root.render(element);
109
+ }
110
+ if (typeof callback === "function") {
111
+ callback();
112
+ }
113
+ }
114
+ function unmountComponentAtNode(container) {
115
+ const root = roots.get(container);
116
+ if (!root) {
117
+ return false;
118
+ }
119
+ (0, import_react_dom.flushSync)(() => {
120
+ root.unmount();
121
+ });
122
+ roots.delete(container);
123
+ return true;
124
+ }
125
+ // Annotate the CommonJS export names for ESM import in node:
126
+ 0 && (module.exports = {
127
+ findDOMNode,
128
+ hydrate,
129
+ render,
130
+ unmountComponentAtNode
131
+ });
132
+ //# sourceMappingURL=react-polyfill-base.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/react-polyfill-base.ts"],
4
+ "sourcesContent": ["import { flushSync } from 'react-dom';\nimport { createRoot, hydrateRoot } from 'react-dom/client';\nimport type { Root } from 'react-dom/client';\n\nconst internalsKey = '_reactInternals';\n\n// HostComponent fiber tag, represents a DOM element like <div>.\nconst HostComponent = 5;\nconst HostText = 6;\n\nfunction findCurrentFiber( fiber: any ): any {\n\tif ( ! fiber.alternate ) {\n\t\t// First mount \u2014 only one version exists, and it's current.\n\t\treturn fiber;\n\t}\n\n\t// Walk up to the HostRoot to figure out which tree this fiber is on.\n\tlet node = fiber;\n\twhile ( node.return ) {\n\t\tnode = node.return;\n\t}\n\n\t// The root's stateNode.current points to the current tree's root fiber.\n\tif ( node.stateNode.current === node ) {\n\t\t// We walked up the current tree, so `fiber` is already current.\n\t\treturn fiber;\n\t}\n\n\t// We walked up the alternate tree \u2014 switch to the current version.\n\treturn fiber.alternate;\n}\n\nfunction findHostFiber( fiber: any ): any {\n\tconst current = findCurrentFiber( fiber );\n\tif ( ! current ) {\n\t\treturn null;\n\t}\n\treturn findHostFiberImpl( current );\n}\n\nfunction findHostFiberImpl( fiber: any ): any {\n\tif ( fiber.tag === HostComponent || fiber.tag === HostText ) {\n\t\treturn fiber;\n\t}\n\n\tlet child = fiber.child;\n\twhile ( child ) {\n\t\tconst hostFiber = findHostFiberImpl( child );\n\t\tif ( hostFiber ) {\n\t\t\treturn hostFiber;\n\t\t}\n\t\tchild = child.sibling;\n\t}\n\n\treturn null;\n}\n\nexport function findDOMNode( instance: any ): Element | Text | null {\n\tif ( instance === null || instance === undefined ) {\n\t\treturn null;\n\t}\n\n\tif ( instance.nodeType !== undefined ) {\n\t\treturn instance as Element | Text;\n\t}\n\n\tconst fiber = instance[ internalsKey ];\n\tif ( fiber === undefined ) {\n\t\tif ( typeof instance.render === 'function' ) {\n\t\t\tthrow new Error( 'Unable to find node on an unmounted component.' );\n\t\t}\n\t\tconst keys = Object.keys( instance ).join( ',' );\n\t\tthrow new Error(\n\t\t\t`Argument appears to not be a ReactComponent. Keys: ${ keys }`\n\t\t);\n\t}\n\n\tconst hostFiber = findHostFiber( fiber );\n\treturn hostFiber?.stateNode ?? null;\n}\n\nconst roots = new WeakMap< Element, Root >();\n\nexport function render(\n\telement: React.ReactNode,\n\tcontainer: Element,\n\tcallback?: () => void\n): void {\n\tlet root = roots.get( container );\n\tif ( ! root ) {\n\t\troot = createRoot( container );\n\t\troots.set( container, root );\n\t}\n\n\tflushSync( () => {\n\t\troot.render( element );\n\t} );\n\n\tif ( typeof callback === 'function' ) {\n\t\tcallback();\n\t}\n}\n\nexport function hydrate(\n\telement: React.ReactNode,\n\tcontainer: Element,\n\tcallback?: () => void\n): void {\n\tlet root = roots.get( container );\n\tif ( ! root ) {\n\t\troot = hydrateRoot( container, element );\n\t\troots.set( container, root );\n\t} else {\n\t\troot.render( element );\n\t}\n\n\tif ( typeof callback === 'function' ) {\n\t\tcallback();\n\t}\n}\n\nexport function unmountComponentAtNode( container: Element ): boolean {\n\tconst root = roots.get( container );\n\tif ( ! root ) {\n\t\treturn false;\n\t}\n\n\tflushSync( () => {\n\t\troot.unmount();\n\t} );\n\troots.delete( container );\n\treturn true;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAA0B;AAC1B,oBAAwC;AAGxC,IAAM,eAAe;AAGrB,IAAM,gBAAgB;AACtB,IAAM,WAAW;AAEjB,SAAS,iBAAkB,OAAkB;AAC5C,MAAK,CAAE,MAAM,WAAY;AAExB,WAAO;AAAA,EACR;AAGA,MAAI,OAAO;AACX,SAAQ,KAAK,QAAS;AACrB,WAAO,KAAK;AAAA,EACb;AAGA,MAAK,KAAK,UAAU,YAAY,MAAO;AAEtC,WAAO;AAAA,EACR;AAGA,SAAO,MAAM;AACd;AAEA,SAAS,cAAe,OAAkB;AACzC,QAAM,UAAU,iBAAkB,KAAM;AACxC,MAAK,CAAE,SAAU;AAChB,WAAO;AAAA,EACR;AACA,SAAO,kBAAmB,OAAQ;AACnC;AAEA,SAAS,kBAAmB,OAAkB;AAC7C,MAAK,MAAM,QAAQ,iBAAiB,MAAM,QAAQ,UAAW;AAC5D,WAAO;AAAA,EACR;AAEA,MAAI,QAAQ,MAAM;AAClB,SAAQ,OAAQ;AACf,UAAM,YAAY,kBAAmB,KAAM;AAC3C,QAAK,WAAY;AAChB,aAAO;AAAA,IACR;AACA,YAAQ,MAAM;AAAA,EACf;AAEA,SAAO;AACR;AAEO,SAAS,YAAa,UAAuC;AACnE,MAAK,aAAa,QAAQ,aAAa,QAAY;AAClD,WAAO;AAAA,EACR;AAEA,MAAK,SAAS,aAAa,QAAY;AACtC,WAAO;AAAA,EACR;AAEA,QAAM,QAAQ,SAAU,YAAa;AACrC,MAAK,UAAU,QAAY;AAC1B,QAAK,OAAO,SAAS,WAAW,YAAa;AAC5C,YAAM,IAAI,MAAO,gDAAiD;AAAA,IACnE;AACA,UAAM,OAAO,OAAO,KAAM,QAAS,EAAE,KAAM,GAAI;AAC/C,UAAM,IAAI;AAAA,MACT,sDAAuD,IAAK;AAAA,IAC7D;AAAA,EACD;AAEA,QAAM,YAAY,cAAe,KAAM;AACvC,SAAO,WAAW,aAAa;AAChC;AAEA,IAAM,QAAQ,oBAAI,QAAyB;AAEpC,SAAS,OACf,SACA,WACA,UACO;AACP,MAAI,OAAO,MAAM,IAAK,SAAU;AAChC,MAAK,CAAE,MAAO;AACb,eAAO,0BAAY,SAAU;AAC7B,UAAM,IAAK,WAAW,IAAK;AAAA,EAC5B;AAEA,kCAAW,MAAM;AAChB,SAAK,OAAQ,OAAQ;AAAA,EACtB,CAAE;AAEF,MAAK,OAAO,aAAa,YAAa;AACrC,aAAS;AAAA,EACV;AACD;AAEO,SAAS,QACf,SACA,WACA,UACO;AACP,MAAI,OAAO,MAAM,IAAK,SAAU;AAChC,MAAK,CAAE,MAAO;AACb,eAAO,2BAAa,WAAW,OAAQ;AACvC,UAAM,IAAK,WAAW,IAAK;AAAA,EAC5B,OAAO;AACN,SAAK,OAAQ,OAAQ;AAAA,EACtB;AAEA,MAAK,OAAO,aAAa,YAAa;AACrC,aAAS;AAAA,EACV;AACD;AAEO,SAAS,uBAAwB,WAA8B;AACrE,QAAM,OAAO,MAAM,IAAK,SAAU;AAClC,MAAK,CAAE,MAAO;AACb,WAAO;AAAA,EACR;AAEA,kCAAW,MAAM;AAChB,SAAK,QAAQ;AAAA,EACd,CAAE;AACF,QAAM,OAAQ,SAAU;AACxB,SAAO;AACR;",
6
+ "names": []
7
+ }
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // packages/element/src/react-polyfill.ts
31
+ var react_polyfill_exports = {};
32
+ __export(react_polyfill_exports, {
33
+ findDOMNode: () => findDOMNode,
34
+ hydrate: () => hydrate,
35
+ render: () => render,
36
+ unmountComponentAtNode: () => unmountComponentAtNode
37
+ });
38
+ module.exports = __toCommonJS(react_polyfill_exports);
39
+ var import_deprecated = __toESM(require("@wordpress/deprecated"));
40
+ var import_react_polyfill_base = require("./react-polyfill-base.cjs");
41
+ function findDOMNode(instance) {
42
+ (0, import_deprecated.default)("wp.element.findDOMNode", {
43
+ since: "7.1",
44
+ alternative: "DOM refs",
45
+ link: "https://react.dev/reference/react-dom/findDOMNode"
46
+ });
47
+ return (0, import_react_polyfill_base.findDOMNode)(instance);
48
+ }
49
+ function render(element, container, callback) {
50
+ (0, import_deprecated.default)("wp.element.render", {
51
+ since: "6.2",
52
+ alternative: "wp.element.createRoot",
53
+ link: "https://react.dev/reference/react-dom/client/createRoot"
54
+ });
55
+ (0, import_react_polyfill_base.render)(element, container, callback);
56
+ }
57
+ function hydrate(element, container, callback) {
58
+ (0, import_deprecated.default)("wp.element.hydrate", {
59
+ since: "6.2",
60
+ alternative: "wp.element.hydrateRoot",
61
+ link: "https://react.dev/reference/react-dom/client/hydrateRoot"
62
+ });
63
+ (0, import_react_polyfill_base.hydrate)(element, container, callback);
64
+ }
65
+ function unmountComponentAtNode(container) {
66
+ (0, import_deprecated.default)("wp.element.unmountComponentAtNode", {
67
+ since: "6.2",
68
+ alternative: "root.unmount()",
69
+ link: "https://react.dev/reference/react-dom/client/createRoot#root-unmount"
70
+ });
71
+ return (0, import_react_polyfill_base.unmountComponentAtNode)(container);
72
+ }
73
+ // Annotate the CommonJS export names for ESM import in node:
74
+ 0 && (module.exports = {
75
+ findDOMNode,
76
+ hydrate,
77
+ render,
78
+ unmountComponentAtNode
79
+ });
80
+ //# sourceMappingURL=react-polyfill.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/react-polyfill.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport {\n\tfindDOMNode as findDOMNodeBase,\n\trender as renderBase,\n\thydrate as hydrateBase,\n\tunmountComponentAtNode as unmountComponentAtNodeBase,\n} from './react-polyfill-base';\n\n/**\n * Finds the DOM node of a React component instance.\n *\n * @deprecated since WordPress 7.1.0. Use DOM refs instead.\n * @see https://react.dev/reference/react-dom/findDOMNode\n *\n * @param instance Component's instance.\n */\nexport function findDOMNode( instance: any ): Element | Text | null {\n\tdeprecated( 'wp.element.findDOMNode', {\n\t\tsince: '7.1',\n\t\talternative: 'DOM refs',\n\t\tlink: 'https://react.dev/reference/react-dom/findDOMNode',\n\t} );\n\n\treturn findDOMNodeBase( instance );\n}\n\n/**\n * Renders a given element into the target DOM node.\n *\n * @deprecated since WordPress 6.2.0. Use `createRoot` instead.\n * @see https://react.dev/reference/react-dom/render\n *\n * @param element Element to render.\n * @param container DOM node into which to render.\n * @param callback Optional callback called after render.\n */\nexport function render(\n\telement: React.ReactNode,\n\tcontainer: Element,\n\tcallback?: () => void\n): void {\n\tdeprecated( 'wp.element.render', {\n\t\tsince: '6.2',\n\t\talternative: 'wp.element.createRoot',\n\t\tlink: 'https://react.dev/reference/react-dom/client/createRoot',\n\t} );\n\n\trenderBase( element, container, callback );\n}\n\n/**\n * Hydrates a given element into the target DOM node.\n *\n * @deprecated since WordPress 6.2.0. Use `hydrateRoot` instead.\n * @see https://react.dev/reference/react-dom/hydrate\n *\n * @param element Element to hydrate.\n * @param container DOM node to hydrate.\n * @param callback Optional callback called after hydration.\n */\nexport function hydrate(\n\telement: React.ReactNode,\n\tcontainer: Element,\n\tcallback?: () => void\n): void {\n\tdeprecated( 'wp.element.hydrate', {\n\t\tsince: '6.2',\n\t\talternative: 'wp.element.hydrateRoot',\n\t\tlink: 'https://react.dev/reference/react-dom/client/hydrateRoot',\n\t} );\n\n\thydrateBase( element, container, callback );\n}\n\n/**\n * Removes any mounted element from the target DOM node.\n *\n * @deprecated since WordPress 6.2.0. Use `root.unmount()` instead.\n * @see https://react.dev/reference/react-dom/unmountComponentAtNode\n *\n * @param container DOM node in which to unmount.\n * @return Whether the node was unmounted.\n */\nexport function unmountComponentAtNode( container: Element ): boolean {\n\tdeprecated( 'wp.element.unmountComponentAtNode', {\n\t\tsince: '6.2',\n\t\talternative: 'root.unmount()',\n\t\tlink: 'https://react.dev/reference/react-dom/client/createRoot#root-unmount',\n\t} );\n\n\treturn unmountComponentAtNodeBase( container );\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,wBAAuB;AAKvB,iCAKO;AAUA,SAAS,YAAa,UAAuC;AACnE,wBAAAA,SAAY,0BAA0B;AAAA,IACrC,OAAO;AAAA,IACP,aAAa;AAAA,IACb,MAAM;AAAA,EACP,CAAE;AAEF,aAAO,2BAAAC,aAAiB,QAAS;AAClC;AAYO,SAAS,OACf,SACA,WACA,UACO;AACP,wBAAAD,SAAY,qBAAqB;AAAA,IAChC,OAAO;AAAA,IACP,aAAa;AAAA,IACb,MAAM;AAAA,EACP,CAAE;AAEF,iCAAAE,QAAY,SAAS,WAAW,QAAS;AAC1C;AAYO,SAAS,QACf,SACA,WACA,UACO;AACP,wBAAAF,SAAY,sBAAsB;AAAA,IACjC,OAAO;AAAA,IACP,aAAa;AAAA,IACb,MAAM;AAAA,EACP,CAAE;AAEF,iCAAAG,SAAa,SAAS,WAAW,QAAS;AAC3C;AAWO,SAAS,uBAAwB,WAA8B;AACrE,wBAAAH,SAAY,qCAAqC;AAAA,IAChD,OAAO;AAAA,IACP,aAAa;AAAA,IACb,MAAM;AAAA,EACP,CAAE;AAEF,aAAO,2BAAAI,wBAA4B,SAAU;AAC9C;",
6
+ "names": ["deprecated", "findDOMNodeBase", "renderBase", "hydrateBase", "unmountComponentAtNodeBase"]
7
+ }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts"],
4
- "sourcesContent": ["export { default as createInterpolateElement } from './create-interpolate-element';\nexport * from './react';\nexport * from './react-platform';\nexport * from './utils';\nexport { default as Platform } from './platform';\nexport { default as renderToString } from './serialize';\nexport { default as RawHTML } from './raw-html';\n"],
4
+ "sourcesContent": ["export { default as createInterpolateElement } from './create-interpolate-element';\nexport * from './react';\nexport * from './react-platform';\nexport * from './utils';\nexport { default as Platform } from './platform';\nexport { default as renderToString } from './serialize';\nexport { default as RawHTML } from './raw-html';\n// export {\n// \tfindDOMNode,\n// \trender,\n// \thydrate,\n// \tunmountComponentAtNode,\n// } from './react-polyfill';\n"],
5
5
  "mappings": ";AAAA,SAAoB,WAAXA,gBAA2C;AACpD,cAAc;AACd,cAAc;AACd,cAAc;AACd,SAAoB,WAAXA,gBAA2B;AACpC,SAAoB,WAAXA,gBAAiC;AAC1C,SAAoB,WAAXA,gBAA0B;",
6
6
  "names": ["default"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/react-platform.ts"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport {\n\tcreatePortal,\n\tfindDOMNode,\n\tflushSync,\n\t/* eslint-disable react/no-deprecated */\n\trender,\n\thydrate,\n\tunmountComponentAtNode,\n\t/* eslint-enable react/no-deprecated */\n} from 'react-dom';\nimport { createRoot, hydrateRoot } from 'react-dom/client';\n\n/**\n * Creates a portal into which a component can be rendered.\n *\n * @see https://github.com/facebook/react/issues/10309#issuecomment-318433235\n *\n * @param {React.ReactElement} child Any renderable child, such as an element,\n * string, or fragment.\n * @param {HTMLElement} container DOM node into which element should be rendered.\n */\nexport { createPortal };\n\n/**\n * Finds the dom node of a React component.\n *\n * @param {React.ComponentType} component Component's instance.\n */\nexport { findDOMNode };\n\n/**\n * Forces React to flush any updates inside the provided callback synchronously.\n *\n * @param {Function} callback Callback to run synchronously.\n */\nexport { flushSync };\n\n/**\n * Renders a given element into the target DOM node.\n *\n * @deprecated since WordPress 6.2.0. Use `createRoot` instead.\n * @see https://react.dev/reference/react-dom/render\n */\nexport { render };\n\n/**\n * Hydrates a given element into the target DOM node.\n *\n * @deprecated since WordPress 6.2.0. Use `hydrateRoot` instead.\n * @see https://react.dev/reference/react-dom/hydrate\n */\nexport { hydrate };\n\n/**\n * Creates a new React root for the target DOM node.\n *\n * @since 6.2.0 Introduced in WordPress core.\n * @see https://react.dev/reference/react-dom/client/createRoot\n */\nexport { createRoot };\n\n/**\n * Creates a new React root for the target DOM node and hydrates it with a pre-generated markup.\n *\n * @since 6.2.0 Introduced in WordPress core.\n * @see https://react.dev/reference/react-dom/client/hydrateRoot\n */\nexport { hydrateRoot };\n\n/**\n * Removes any mounted element from the target DOM node.\n *\n * @deprecated since WordPress 6.2.0. Use `root.unmount()` instead.\n * @see https://react.dev/reference/react-dom/unmountComponentAtNode\n */\nexport { unmountComponentAtNode };\n"],
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport {\n\tcreatePortal,\n\tfindDOMNode,\n\tflushSync,\n\t/* eslint-disable react/no-deprecated */\n\trender,\n\thydrate,\n\tunmountComponentAtNode,\n\t/* eslint-enable react/no-deprecated */\n} from 'react-dom';\nimport { createRoot, hydrateRoot } from 'react-dom/client';\n\n/**\n * Creates a portal into which a component can be rendered.\n *\n * @see https://react.dev/reference/react-dom/createPortal\n */\nexport { createPortal };\n\n/**\n * Finds the dom node of a React component.\n *\n * @param {React.ComponentType} component Component's instance.\n */\nexport { findDOMNode };\n\n/**\n * Forces React to flush any updates inside the provided callback synchronously.\n *\n * @see https://react.dev/reference/react-dom/flushSync\n */\nexport { flushSync };\n\n/**\n * Renders a given element into the target DOM node.\n *\n * @deprecated since WordPress 6.2.0. Use `createRoot` instead.\n * @see https://react.dev/reference/react-dom/render\n */\nexport { render };\n\n/**\n * Hydrates a given element into the target DOM node.\n *\n * @deprecated since WordPress 6.2.0. Use `hydrateRoot` instead.\n * @see https://react.dev/reference/react-dom/hydrate\n */\nexport { hydrate };\n\n/**\n * Creates a new React root for the target DOM node.\n *\n * @since 6.2.0 Introduced in WordPress core.\n * @see https://react.dev/reference/react-dom/client/createRoot\n */\nexport { createRoot };\n\n/**\n * Creates a new React root for the target DOM node and hydrates it with a pre-generated markup.\n *\n * @since 6.2.0 Introduced in WordPress core.\n * @see https://react.dev/reference/react-dom/client/hydrateRoot\n */\nexport { hydrateRoot };\n\n/**\n * Removes any mounted element from the target DOM node.\n *\n * @deprecated since WordPress 6.2.0. Use `root.unmount()` instead.\n * @see https://react.dev/reference/react-dom/unmountComponentAtNode\n */\nexport { unmountComponentAtNode };\n"],
5
5
  "mappings": ";AAGA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OAEM;AACP,SAAS,YAAY,mBAAmB;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,104 @@
1
+ // packages/element/src/react-polyfill-base.ts
2
+ import { flushSync } from "react-dom";
3
+ import { createRoot, hydrateRoot } from "react-dom/client";
4
+ var internalsKey = "_reactInternals";
5
+ var HostComponent = 5;
6
+ var HostText = 6;
7
+ function findCurrentFiber(fiber) {
8
+ if (!fiber.alternate) {
9
+ return fiber;
10
+ }
11
+ let node = fiber;
12
+ while (node.return) {
13
+ node = node.return;
14
+ }
15
+ if (node.stateNode.current === node) {
16
+ return fiber;
17
+ }
18
+ return fiber.alternate;
19
+ }
20
+ function findHostFiber(fiber) {
21
+ const current = findCurrentFiber(fiber);
22
+ if (!current) {
23
+ return null;
24
+ }
25
+ return findHostFiberImpl(current);
26
+ }
27
+ function findHostFiberImpl(fiber) {
28
+ if (fiber.tag === HostComponent || fiber.tag === HostText) {
29
+ return fiber;
30
+ }
31
+ let child = fiber.child;
32
+ while (child) {
33
+ const hostFiber = findHostFiberImpl(child);
34
+ if (hostFiber) {
35
+ return hostFiber;
36
+ }
37
+ child = child.sibling;
38
+ }
39
+ return null;
40
+ }
41
+ function findDOMNode(instance) {
42
+ if (instance === null || instance === void 0) {
43
+ return null;
44
+ }
45
+ if (instance.nodeType !== void 0) {
46
+ return instance;
47
+ }
48
+ const fiber = instance[internalsKey];
49
+ if (fiber === void 0) {
50
+ if (typeof instance.render === "function") {
51
+ throw new Error("Unable to find node on an unmounted component.");
52
+ }
53
+ const keys = Object.keys(instance).join(",");
54
+ throw new Error(
55
+ `Argument appears to not be a ReactComponent. Keys: ${keys}`
56
+ );
57
+ }
58
+ const hostFiber = findHostFiber(fiber);
59
+ return hostFiber?.stateNode ?? null;
60
+ }
61
+ var roots = /* @__PURE__ */ new WeakMap();
62
+ function render(element, container, callback) {
63
+ let root = roots.get(container);
64
+ if (!root) {
65
+ root = createRoot(container);
66
+ roots.set(container, root);
67
+ }
68
+ flushSync(() => {
69
+ root.render(element);
70
+ });
71
+ if (typeof callback === "function") {
72
+ callback();
73
+ }
74
+ }
75
+ function hydrate(element, container, callback) {
76
+ let root = roots.get(container);
77
+ if (!root) {
78
+ root = hydrateRoot(container, element);
79
+ roots.set(container, root);
80
+ } else {
81
+ root.render(element);
82
+ }
83
+ if (typeof callback === "function") {
84
+ callback();
85
+ }
86
+ }
87
+ function unmountComponentAtNode(container) {
88
+ const root = roots.get(container);
89
+ if (!root) {
90
+ return false;
91
+ }
92
+ flushSync(() => {
93
+ root.unmount();
94
+ });
95
+ roots.delete(container);
96
+ return true;
97
+ }
98
+ export {
99
+ findDOMNode,
100
+ hydrate,
101
+ render,
102
+ unmountComponentAtNode
103
+ };
104
+ //# sourceMappingURL=react-polyfill-base.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/react-polyfill-base.ts"],
4
+ "sourcesContent": ["import { flushSync } from 'react-dom';\nimport { createRoot, hydrateRoot } from 'react-dom/client';\nimport type { Root } from 'react-dom/client';\n\nconst internalsKey = '_reactInternals';\n\n// HostComponent fiber tag, represents a DOM element like <div>.\nconst HostComponent = 5;\nconst HostText = 6;\n\nfunction findCurrentFiber( fiber: any ): any {\n\tif ( ! fiber.alternate ) {\n\t\t// First mount \u2014 only one version exists, and it's current.\n\t\treturn fiber;\n\t}\n\n\t// Walk up to the HostRoot to figure out which tree this fiber is on.\n\tlet node = fiber;\n\twhile ( node.return ) {\n\t\tnode = node.return;\n\t}\n\n\t// The root's stateNode.current points to the current tree's root fiber.\n\tif ( node.stateNode.current === node ) {\n\t\t// We walked up the current tree, so `fiber` is already current.\n\t\treturn fiber;\n\t}\n\n\t// We walked up the alternate tree \u2014 switch to the current version.\n\treturn fiber.alternate;\n}\n\nfunction findHostFiber( fiber: any ): any {\n\tconst current = findCurrentFiber( fiber );\n\tif ( ! current ) {\n\t\treturn null;\n\t}\n\treturn findHostFiberImpl( current );\n}\n\nfunction findHostFiberImpl( fiber: any ): any {\n\tif ( fiber.tag === HostComponent || fiber.tag === HostText ) {\n\t\treturn fiber;\n\t}\n\n\tlet child = fiber.child;\n\twhile ( child ) {\n\t\tconst hostFiber = findHostFiberImpl( child );\n\t\tif ( hostFiber ) {\n\t\t\treturn hostFiber;\n\t\t}\n\t\tchild = child.sibling;\n\t}\n\n\treturn null;\n}\n\nexport function findDOMNode( instance: any ): Element | Text | null {\n\tif ( instance === null || instance === undefined ) {\n\t\treturn null;\n\t}\n\n\tif ( instance.nodeType !== undefined ) {\n\t\treturn instance as Element | Text;\n\t}\n\n\tconst fiber = instance[ internalsKey ];\n\tif ( fiber === undefined ) {\n\t\tif ( typeof instance.render === 'function' ) {\n\t\t\tthrow new Error( 'Unable to find node on an unmounted component.' );\n\t\t}\n\t\tconst keys = Object.keys( instance ).join( ',' );\n\t\tthrow new Error(\n\t\t\t`Argument appears to not be a ReactComponent. Keys: ${ keys }`\n\t\t);\n\t}\n\n\tconst hostFiber = findHostFiber( fiber );\n\treturn hostFiber?.stateNode ?? null;\n}\n\nconst roots = new WeakMap< Element, Root >();\n\nexport function render(\n\telement: React.ReactNode,\n\tcontainer: Element,\n\tcallback?: () => void\n): void {\n\tlet root = roots.get( container );\n\tif ( ! root ) {\n\t\troot = createRoot( container );\n\t\troots.set( container, root );\n\t}\n\n\tflushSync( () => {\n\t\troot.render( element );\n\t} );\n\n\tif ( typeof callback === 'function' ) {\n\t\tcallback();\n\t}\n}\n\nexport function hydrate(\n\telement: React.ReactNode,\n\tcontainer: Element,\n\tcallback?: () => void\n): void {\n\tlet root = roots.get( container );\n\tif ( ! root ) {\n\t\troot = hydrateRoot( container, element );\n\t\troots.set( container, root );\n\t} else {\n\t\troot.render( element );\n\t}\n\n\tif ( typeof callback === 'function' ) {\n\t\tcallback();\n\t}\n}\n\nexport function unmountComponentAtNode( container: Element ): boolean {\n\tconst root = roots.get( container );\n\tif ( ! root ) {\n\t\treturn false;\n\t}\n\n\tflushSync( () => {\n\t\troot.unmount();\n\t} );\n\troots.delete( container );\n\treturn true;\n}\n"],
5
+ "mappings": ";AAAA,SAAS,iBAAiB;AAC1B,SAAS,YAAY,mBAAmB;AAGxC,IAAM,eAAe;AAGrB,IAAM,gBAAgB;AACtB,IAAM,WAAW;AAEjB,SAAS,iBAAkB,OAAkB;AAC5C,MAAK,CAAE,MAAM,WAAY;AAExB,WAAO;AAAA,EACR;AAGA,MAAI,OAAO;AACX,SAAQ,KAAK,QAAS;AACrB,WAAO,KAAK;AAAA,EACb;AAGA,MAAK,KAAK,UAAU,YAAY,MAAO;AAEtC,WAAO;AAAA,EACR;AAGA,SAAO,MAAM;AACd;AAEA,SAAS,cAAe,OAAkB;AACzC,QAAM,UAAU,iBAAkB,KAAM;AACxC,MAAK,CAAE,SAAU;AAChB,WAAO;AAAA,EACR;AACA,SAAO,kBAAmB,OAAQ;AACnC;AAEA,SAAS,kBAAmB,OAAkB;AAC7C,MAAK,MAAM,QAAQ,iBAAiB,MAAM,QAAQ,UAAW;AAC5D,WAAO;AAAA,EACR;AAEA,MAAI,QAAQ,MAAM;AAClB,SAAQ,OAAQ;AACf,UAAM,YAAY,kBAAmB,KAAM;AAC3C,QAAK,WAAY;AAChB,aAAO;AAAA,IACR;AACA,YAAQ,MAAM;AAAA,EACf;AAEA,SAAO;AACR;AAEO,SAAS,YAAa,UAAuC;AACnE,MAAK,aAAa,QAAQ,aAAa,QAAY;AAClD,WAAO;AAAA,EACR;AAEA,MAAK,SAAS,aAAa,QAAY;AACtC,WAAO;AAAA,EACR;AAEA,QAAM,QAAQ,SAAU,YAAa;AACrC,MAAK,UAAU,QAAY;AAC1B,QAAK,OAAO,SAAS,WAAW,YAAa;AAC5C,YAAM,IAAI,MAAO,gDAAiD;AAAA,IACnE;AACA,UAAM,OAAO,OAAO,KAAM,QAAS,EAAE,KAAM,GAAI;AAC/C,UAAM,IAAI;AAAA,MACT,sDAAuD,IAAK;AAAA,IAC7D;AAAA,EACD;AAEA,QAAM,YAAY,cAAe,KAAM;AACvC,SAAO,WAAW,aAAa;AAChC;AAEA,IAAM,QAAQ,oBAAI,QAAyB;AAEpC,SAAS,OACf,SACA,WACA,UACO;AACP,MAAI,OAAO,MAAM,IAAK,SAAU;AAChC,MAAK,CAAE,MAAO;AACb,WAAO,WAAY,SAAU;AAC7B,UAAM,IAAK,WAAW,IAAK;AAAA,EAC5B;AAEA,YAAW,MAAM;AAChB,SAAK,OAAQ,OAAQ;AAAA,EACtB,CAAE;AAEF,MAAK,OAAO,aAAa,YAAa;AACrC,aAAS;AAAA,EACV;AACD;AAEO,SAAS,QACf,SACA,WACA,UACO;AACP,MAAI,OAAO,MAAM,IAAK,SAAU;AAChC,MAAK,CAAE,MAAO;AACb,WAAO,YAAa,WAAW,OAAQ;AACvC,UAAM,IAAK,WAAW,IAAK;AAAA,EAC5B,OAAO;AACN,SAAK,OAAQ,OAAQ;AAAA,EACtB;AAEA,MAAK,OAAO,aAAa,YAAa;AACrC,aAAS;AAAA,EACV;AACD;AAEO,SAAS,uBAAwB,WAA8B;AACrE,QAAM,OAAO,MAAM,IAAK,SAAU;AAClC,MAAK,CAAE,MAAO;AACb,WAAO;AAAA,EACR;AAEA,YAAW,MAAM;AAChB,SAAK,QAAQ;AAAA,EACd,CAAE;AACF,QAAM,OAAQ,SAAU;AACxB,SAAO;AACR;",
6
+ "names": []
7
+ }
@@ -0,0 +1,47 @@
1
+ // packages/element/src/react-polyfill.ts
2
+ import deprecated from "@wordpress/deprecated";
3
+ import {
4
+ findDOMNode as findDOMNodeBase,
5
+ render as renderBase,
6
+ hydrate as hydrateBase,
7
+ unmountComponentAtNode as unmountComponentAtNodeBase
8
+ } from "./react-polyfill-base.mjs";
9
+ function findDOMNode(instance) {
10
+ deprecated("wp.element.findDOMNode", {
11
+ since: "7.1",
12
+ alternative: "DOM refs",
13
+ link: "https://react.dev/reference/react-dom/findDOMNode"
14
+ });
15
+ return findDOMNodeBase(instance);
16
+ }
17
+ function render(element, container, callback) {
18
+ deprecated("wp.element.render", {
19
+ since: "6.2",
20
+ alternative: "wp.element.createRoot",
21
+ link: "https://react.dev/reference/react-dom/client/createRoot"
22
+ });
23
+ renderBase(element, container, callback);
24
+ }
25
+ function hydrate(element, container, callback) {
26
+ deprecated("wp.element.hydrate", {
27
+ since: "6.2",
28
+ alternative: "wp.element.hydrateRoot",
29
+ link: "https://react.dev/reference/react-dom/client/hydrateRoot"
30
+ });
31
+ hydrateBase(element, container, callback);
32
+ }
33
+ function unmountComponentAtNode(container) {
34
+ deprecated("wp.element.unmountComponentAtNode", {
35
+ since: "6.2",
36
+ alternative: "root.unmount()",
37
+ link: "https://react.dev/reference/react-dom/client/createRoot#root-unmount"
38
+ });
39
+ return unmountComponentAtNodeBase(container);
40
+ }
41
+ export {
42
+ findDOMNode,
43
+ hydrate,
44
+ render,
45
+ unmountComponentAtNode
46
+ };
47
+ //# sourceMappingURL=react-polyfill.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/react-polyfill.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport {\n\tfindDOMNode as findDOMNodeBase,\n\trender as renderBase,\n\thydrate as hydrateBase,\n\tunmountComponentAtNode as unmountComponentAtNodeBase,\n} from './react-polyfill-base';\n\n/**\n * Finds the DOM node of a React component instance.\n *\n * @deprecated since WordPress 7.1.0. Use DOM refs instead.\n * @see https://react.dev/reference/react-dom/findDOMNode\n *\n * @param instance Component's instance.\n */\nexport function findDOMNode( instance: any ): Element | Text | null {\n\tdeprecated( 'wp.element.findDOMNode', {\n\t\tsince: '7.1',\n\t\talternative: 'DOM refs',\n\t\tlink: 'https://react.dev/reference/react-dom/findDOMNode',\n\t} );\n\n\treturn findDOMNodeBase( instance );\n}\n\n/**\n * Renders a given element into the target DOM node.\n *\n * @deprecated since WordPress 6.2.0. Use `createRoot` instead.\n * @see https://react.dev/reference/react-dom/render\n *\n * @param element Element to render.\n * @param container DOM node into which to render.\n * @param callback Optional callback called after render.\n */\nexport function render(\n\telement: React.ReactNode,\n\tcontainer: Element,\n\tcallback?: () => void\n): void {\n\tdeprecated( 'wp.element.render', {\n\t\tsince: '6.2',\n\t\talternative: 'wp.element.createRoot',\n\t\tlink: 'https://react.dev/reference/react-dom/client/createRoot',\n\t} );\n\n\trenderBase( element, container, callback );\n}\n\n/**\n * Hydrates a given element into the target DOM node.\n *\n * @deprecated since WordPress 6.2.0. Use `hydrateRoot` instead.\n * @see https://react.dev/reference/react-dom/hydrate\n *\n * @param element Element to hydrate.\n * @param container DOM node to hydrate.\n * @param callback Optional callback called after hydration.\n */\nexport function hydrate(\n\telement: React.ReactNode,\n\tcontainer: Element,\n\tcallback?: () => void\n): void {\n\tdeprecated( 'wp.element.hydrate', {\n\t\tsince: '6.2',\n\t\talternative: 'wp.element.hydrateRoot',\n\t\tlink: 'https://react.dev/reference/react-dom/client/hydrateRoot',\n\t} );\n\n\thydrateBase( element, container, callback );\n}\n\n/**\n * Removes any mounted element from the target DOM node.\n *\n * @deprecated since WordPress 6.2.0. Use `root.unmount()` instead.\n * @see https://react.dev/reference/react-dom/unmountComponentAtNode\n *\n * @param container DOM node in which to unmount.\n * @return Whether the node was unmounted.\n */\nexport function unmountComponentAtNode( container: Element ): boolean {\n\tdeprecated( 'wp.element.unmountComponentAtNode', {\n\t\tsince: '6.2',\n\t\talternative: 'root.unmount()',\n\t\tlink: 'https://react.dev/reference/react-dom/client/createRoot#root-unmount',\n\t} );\n\n\treturn unmountComponentAtNodeBase( container );\n}\n"],
5
+ "mappings": ";AAGA,OAAO,gBAAgB;AAKvB;AAAA,EACC,eAAe;AAAA,EACf,UAAU;AAAA,EACV,WAAW;AAAA,EACX,0BAA0B;AAAA,OACpB;AAUA,SAAS,YAAa,UAAuC;AACnE,aAAY,0BAA0B;AAAA,IACrC,OAAO;AAAA,IACP,aAAa;AAAA,IACb,MAAM;AAAA,EACP,CAAE;AAEF,SAAO,gBAAiB,QAAS;AAClC;AAYO,SAAS,OACf,SACA,WACA,UACO;AACP,aAAY,qBAAqB;AAAA,IAChC,OAAO;AAAA,IACP,aAAa;AAAA,IACb,MAAM;AAAA,EACP,CAAE;AAEF,aAAY,SAAS,WAAW,QAAS;AAC1C;AAYO,SAAS,QACf,SACA,WACA,UACO;AACP,aAAY,sBAAsB;AAAA,IACjC,OAAO;AAAA,IACP,aAAa;AAAA,IACb,MAAM;AAAA,EACP,CAAE;AAEF,cAAa,SAAS,WAAW,QAAS;AAC3C;AAWO,SAAS,uBAAwB,WAA8B;AACrE,aAAY,qCAAqC;AAAA,IAChD,OAAO;AAAA,IACP,aAAa;AAAA,IACb,MAAM;AAAA,EACP,CAAE;AAEF,SAAO,2BAA4B,SAAU;AAC9C;",
6
+ "names": []
7
+ }
@@ -6,11 +6,7 @@ import { createRoot, hydrateRoot } from 'react-dom/client';
6
6
  /**
7
7
  * Creates a portal into which a component can be rendered.
8
8
  *
9
- * @see https://github.com/facebook/react/issues/10309#issuecomment-318433235
10
- *
11
- * @param {React.ReactElement} child Any renderable child, such as an element,
12
- * string, or fragment.
13
- * @param {HTMLElement} container DOM node into which element should be rendered.
9
+ * @see https://react.dev/reference/react-dom/createPortal
14
10
  */
15
11
  export { createPortal };
16
12
  /**
@@ -22,7 +18,7 @@ export { findDOMNode };
22
18
  /**
23
19
  * Forces React to flush any updates inside the provided callback synchronously.
24
20
  *
25
- * @param {Function} callback Callback to run synchronously.
21
+ * @see https://react.dev/reference/react-dom/flushSync
26
22
  */
27
23
  export { flushSync };
28
24
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"react-platform.d.ts","sourceRoot":"","sources":["../src/react-platform.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACN,YAAY,EACZ,WAAW,EACX,SAAS,EAET,MAAM,EACN,OAAO,EACP,sBAAsB,EAEtB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE3D;;;;;;;;GAQG;AACH,OAAO,EAAE,YAAY,EAAE,CAAC;AAExB;;;;GAIG;AACH,OAAO,EAAE,WAAW,EAAE,CAAC;AAEvB;;;;GAIG;AACH,OAAO,EAAE,SAAS,EAAE,CAAC;AAErB;;;;;GAKG;AACH,OAAO,EAAE,MAAM,EAAE,CAAC;AAElB;;;;;GAKG;AACH,OAAO,EAAE,OAAO,EAAE,CAAC;AAEnB;;;;;GAKG;AACH,OAAO,EAAE,UAAU,EAAE,CAAC;AAEtB;;;;;GAKG;AACH,OAAO,EAAE,WAAW,EAAE,CAAC;AAEvB;;;;;GAKG;AACH,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
1
+ {"version":3,"file":"react-platform.d.ts","sourceRoot":"","sources":["../src/react-platform.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACN,YAAY,EACZ,WAAW,EACX,SAAS,EAET,MAAM,EACN,OAAO,EACP,sBAAsB,EAEtB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE3D;;;;GAIG;AACH,OAAO,EAAE,YAAY,EAAE,CAAC;AAExB;;;;GAIG;AACH,OAAO,EAAE,WAAW,EAAE,CAAC;AAEvB;;;;GAIG;AACH,OAAO,EAAE,SAAS,EAAE,CAAC;AAErB;;;;;GAKG;AACH,OAAO,EAAE,MAAM,EAAE,CAAC;AAElB;;;;;GAKG;AACH,OAAO,EAAE,OAAO,EAAE,CAAC;AAEnB;;;;;GAKG;AACH,OAAO,EAAE,UAAU,EAAE,CAAC;AAEtB;;;;;GAKG;AACH,OAAO,EAAE,WAAW,EAAE,CAAC;AAEvB;;;;;GAKG;AACH,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
@@ -0,0 +1,5 @@
1
+ export declare function findDOMNode(instance: any): Element | Text | null;
2
+ export declare function render(element: React.ReactNode, container: Element, callback?: () => void): void;
3
+ export declare function hydrate(element: React.ReactNode, container: Element, callback?: () => void): void;
4
+ export declare function unmountComponentAtNode(container: Element): boolean;
5
+ //# sourceMappingURL=react-polyfill-base.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-polyfill-base.d.ts","sourceRoot":"","sources":["../src/react-polyfill-base.ts"],"names":[],"mappings":"AAyDA,wBAAgB,WAAW,CAAE,QAAQ,EAAE,GAAG,GAAI,OAAO,GAAG,IAAI,GAAG,IAAI,CAsBlE;AAID,wBAAgB,MAAM,CACrB,OAAO,EAAE,KAAK,CAAC,SAAS,EACxB,SAAS,EAAE,OAAO,EAClB,QAAQ,CAAC,EAAE,MAAM,IAAI,GACnB,IAAI,CAcN;AAED,wBAAgB,OAAO,CACtB,OAAO,EAAE,KAAK,CAAC,SAAS,EACxB,SAAS,EAAE,OAAO,EAClB,QAAQ,CAAC,EAAE,MAAM,IAAI,GACnB,IAAI,CAYN;AAED,wBAAgB,sBAAsB,CAAE,SAAS,EAAE,OAAO,GAAI,OAAO,CAWpE"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Finds the DOM node of a React component instance.
3
+ *
4
+ * @deprecated since WordPress 7.1.0. Use DOM refs instead.
5
+ * @see https://react.dev/reference/react-dom/findDOMNode
6
+ *
7
+ * @param instance Component's instance.
8
+ */
9
+ export declare function findDOMNode(instance: any): Element | Text | null;
10
+ /**
11
+ * Renders a given element into the target DOM node.
12
+ *
13
+ * @deprecated since WordPress 6.2.0. Use `createRoot` instead.
14
+ * @see https://react.dev/reference/react-dom/render
15
+ *
16
+ * @param element Element to render.
17
+ * @param container DOM node into which to render.
18
+ * @param callback Optional callback called after render.
19
+ */
20
+ export declare function render(element: React.ReactNode, container: Element, callback?: () => void): void;
21
+ /**
22
+ * Hydrates a given element into the target DOM node.
23
+ *
24
+ * @deprecated since WordPress 6.2.0. Use `hydrateRoot` instead.
25
+ * @see https://react.dev/reference/react-dom/hydrate
26
+ *
27
+ * @param element Element to hydrate.
28
+ * @param container DOM node to hydrate.
29
+ * @param callback Optional callback called after hydration.
30
+ */
31
+ export declare function hydrate(element: React.ReactNode, container: Element, callback?: () => void): void;
32
+ /**
33
+ * Removes any mounted element from the target DOM node.
34
+ *
35
+ * @deprecated since WordPress 6.2.0. Use `root.unmount()` instead.
36
+ * @see https://react.dev/reference/react-dom/unmountComponentAtNode
37
+ *
38
+ * @param container DOM node in which to unmount.
39
+ * @return Whether the node was unmounted.
40
+ */
41
+ export declare function unmountComponentAtNode(container: Element): boolean;
42
+ //# sourceMappingURL=react-polyfill.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"react-polyfill.d.ts","sourceRoot":"","sources":["../src/react-polyfill.ts"],"names":[],"mappings":"AAeA;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAE,QAAQ,EAAE,GAAG,GAAI,OAAO,GAAG,IAAI,GAAG,IAAI,CAQlE;AAED;;;;;;;;;GASG;AACH,wBAAgB,MAAM,CACrB,OAAO,EAAE,KAAK,CAAC,SAAS,EACxB,SAAS,EAAE,OAAO,EAClB,QAAQ,CAAC,EAAE,MAAM,IAAI,GACnB,IAAI,CAQN;AAED;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CACtB,OAAO,EAAE,KAAK,CAAC,SAAS,EACxB,SAAS,EAAE,OAAO,EAClB,QAAQ,CAAC,EAAE,MAAM,IAAI,GACnB,IAAI,CAQN;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAE,SAAS,EAAE,OAAO,GAAI,OAAO,CAQpE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/element",
3
- "version": "6.46.0",
3
+ "version": "8.0.0",
4
4
  "description": "Element React module for WordPress.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -38,6 +38,7 @@
38
38
  "import": "./build-module/index.mjs",
39
39
  "require": "./build/index.cjs"
40
40
  },
41
+ "./react-polyfill": "./src/react-polyfill-base.ts",
41
42
  "./package.json": "./package.json"
42
43
  },
43
44
  "react-native": "src/index",
@@ -47,7 +48,8 @@
47
48
  "dependencies": {
48
49
  "@types/react": "^18.3.27",
49
50
  "@types/react-dom": "^18.3.1",
50
- "@wordpress/escape-html": "^3.46.0",
51
+ "@wordpress/deprecated": "^4.48.0",
52
+ "@wordpress/escape-html": "^3.48.0",
51
53
  "change-case": "^4.1.2",
52
54
  "is-plain-object": "^5.0.0",
53
55
  "react": "^18.3.0",
@@ -56,5 +58,5 @@
56
58
  "publishConfig": {
57
59
  "access": "public"
58
60
  },
59
- "gitHead": "51264e33b95fadff9a06b68141e674ce9cde9675"
61
+ "gitHead": "e7856693aeb4e2522d13608cd32c994e4a97cb9c"
60
62
  }
package/src/index.ts CHANGED
@@ -5,3 +5,9 @@ export * from './utils';
5
5
  export { default as Platform } from './platform';
6
6
  export { default as renderToString } from './serialize';
7
7
  export { default as RawHTML } from './raw-html';
8
+ // export {
9
+ // findDOMNode,
10
+ // render,
11
+ // hydrate,
12
+ // unmountComponentAtNode,
13
+ // } from './react-polyfill';
@@ -16,11 +16,7 @@ import { createRoot, hydrateRoot } from 'react-dom/client';
16
16
  /**
17
17
  * Creates a portal into which a component can be rendered.
18
18
  *
19
- * @see https://github.com/facebook/react/issues/10309#issuecomment-318433235
20
- *
21
- * @param {React.ReactElement} child Any renderable child, such as an element,
22
- * string, or fragment.
23
- * @param {HTMLElement} container DOM node into which element should be rendered.
19
+ * @see https://react.dev/reference/react-dom/createPortal
24
20
  */
25
21
  export { createPortal };
26
22
 
@@ -34,7 +30,7 @@ export { findDOMNode };
34
30
  /**
35
31
  * Forces React to flush any updates inside the provided callback synchronously.
36
32
  *
37
- * @param {Function} callback Callback to run synchronously.
33
+ * @see https://react.dev/reference/react-dom/flushSync
38
34
  */
39
35
  export { flushSync };
40
36
 
@@ -0,0 +1,133 @@
1
+ import { flushSync } from 'react-dom';
2
+ import { createRoot, hydrateRoot } from 'react-dom/client';
3
+ import type { Root } from 'react-dom/client';
4
+
5
+ const internalsKey = '_reactInternals';
6
+
7
+ // HostComponent fiber tag, represents a DOM element like <div>.
8
+ const HostComponent = 5;
9
+ const HostText = 6;
10
+
11
+ function findCurrentFiber( fiber: any ): any {
12
+ if ( ! fiber.alternate ) {
13
+ // First mount — only one version exists, and it's current.
14
+ return fiber;
15
+ }
16
+
17
+ // Walk up to the HostRoot to figure out which tree this fiber is on.
18
+ let node = fiber;
19
+ while ( node.return ) {
20
+ node = node.return;
21
+ }
22
+
23
+ // The root's stateNode.current points to the current tree's root fiber.
24
+ if ( node.stateNode.current === node ) {
25
+ // We walked up the current tree, so `fiber` is already current.
26
+ return fiber;
27
+ }
28
+
29
+ // We walked up the alternate tree — switch to the current version.
30
+ return fiber.alternate;
31
+ }
32
+
33
+ function findHostFiber( fiber: any ): any {
34
+ const current = findCurrentFiber( fiber );
35
+ if ( ! current ) {
36
+ return null;
37
+ }
38
+ return findHostFiberImpl( current );
39
+ }
40
+
41
+ function findHostFiberImpl( fiber: any ): any {
42
+ if ( fiber.tag === HostComponent || fiber.tag === HostText ) {
43
+ return fiber;
44
+ }
45
+
46
+ let child = fiber.child;
47
+ while ( child ) {
48
+ const hostFiber = findHostFiberImpl( child );
49
+ if ( hostFiber ) {
50
+ return hostFiber;
51
+ }
52
+ child = child.sibling;
53
+ }
54
+
55
+ return null;
56
+ }
57
+
58
+ export function findDOMNode( instance: any ): Element | Text | null {
59
+ if ( instance === null || instance === undefined ) {
60
+ return null;
61
+ }
62
+
63
+ if ( instance.nodeType !== undefined ) {
64
+ return instance as Element | Text;
65
+ }
66
+
67
+ const fiber = instance[ internalsKey ];
68
+ if ( fiber === undefined ) {
69
+ if ( typeof instance.render === 'function' ) {
70
+ throw new Error( 'Unable to find node on an unmounted component.' );
71
+ }
72
+ const keys = Object.keys( instance ).join( ',' );
73
+ throw new Error(
74
+ `Argument appears to not be a ReactComponent. Keys: ${ keys }`
75
+ );
76
+ }
77
+
78
+ const hostFiber = findHostFiber( fiber );
79
+ return hostFiber?.stateNode ?? null;
80
+ }
81
+
82
+ const roots = new WeakMap< Element, Root >();
83
+
84
+ export function render(
85
+ element: React.ReactNode,
86
+ container: Element,
87
+ callback?: () => void
88
+ ): void {
89
+ let root = roots.get( container );
90
+ if ( ! root ) {
91
+ root = createRoot( container );
92
+ roots.set( container, root );
93
+ }
94
+
95
+ flushSync( () => {
96
+ root.render( element );
97
+ } );
98
+
99
+ if ( typeof callback === 'function' ) {
100
+ callback();
101
+ }
102
+ }
103
+
104
+ export function hydrate(
105
+ element: React.ReactNode,
106
+ container: Element,
107
+ callback?: () => void
108
+ ): void {
109
+ let root = roots.get( container );
110
+ if ( ! root ) {
111
+ root = hydrateRoot( container, element );
112
+ roots.set( container, root );
113
+ } else {
114
+ root.render( element );
115
+ }
116
+
117
+ if ( typeof callback === 'function' ) {
118
+ callback();
119
+ }
120
+ }
121
+
122
+ export function unmountComponentAtNode( container: Element ): boolean {
123
+ const root = roots.get( container );
124
+ if ( ! root ) {
125
+ return false;
126
+ }
127
+
128
+ flushSync( () => {
129
+ root.unmount();
130
+ } );
131
+ roots.delete( container );
132
+ return true;
133
+ }
@@ -0,0 +1,99 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import deprecated from '@wordpress/deprecated';
5
+
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+ import {
10
+ findDOMNode as findDOMNodeBase,
11
+ render as renderBase,
12
+ hydrate as hydrateBase,
13
+ unmountComponentAtNode as unmountComponentAtNodeBase,
14
+ } from './react-polyfill-base';
15
+
16
+ /**
17
+ * Finds the DOM node of a React component instance.
18
+ *
19
+ * @deprecated since WordPress 7.1.0. Use DOM refs instead.
20
+ * @see https://react.dev/reference/react-dom/findDOMNode
21
+ *
22
+ * @param instance Component's instance.
23
+ */
24
+ export function findDOMNode( instance: any ): Element | Text | null {
25
+ deprecated( 'wp.element.findDOMNode', {
26
+ since: '7.1',
27
+ alternative: 'DOM refs',
28
+ link: 'https://react.dev/reference/react-dom/findDOMNode',
29
+ } );
30
+
31
+ return findDOMNodeBase( instance );
32
+ }
33
+
34
+ /**
35
+ * Renders a given element into the target DOM node.
36
+ *
37
+ * @deprecated since WordPress 6.2.0. Use `createRoot` instead.
38
+ * @see https://react.dev/reference/react-dom/render
39
+ *
40
+ * @param element Element to render.
41
+ * @param container DOM node into which to render.
42
+ * @param callback Optional callback called after render.
43
+ */
44
+ export function render(
45
+ element: React.ReactNode,
46
+ container: Element,
47
+ callback?: () => void
48
+ ): void {
49
+ deprecated( 'wp.element.render', {
50
+ since: '6.2',
51
+ alternative: 'wp.element.createRoot',
52
+ link: 'https://react.dev/reference/react-dom/client/createRoot',
53
+ } );
54
+
55
+ renderBase( element, container, callback );
56
+ }
57
+
58
+ /**
59
+ * Hydrates a given element into the target DOM node.
60
+ *
61
+ * @deprecated since WordPress 6.2.0. Use `hydrateRoot` instead.
62
+ * @see https://react.dev/reference/react-dom/hydrate
63
+ *
64
+ * @param element Element to hydrate.
65
+ * @param container DOM node to hydrate.
66
+ * @param callback Optional callback called after hydration.
67
+ */
68
+ export function hydrate(
69
+ element: React.ReactNode,
70
+ container: Element,
71
+ callback?: () => void
72
+ ): void {
73
+ deprecated( 'wp.element.hydrate', {
74
+ since: '6.2',
75
+ alternative: 'wp.element.hydrateRoot',
76
+ link: 'https://react.dev/reference/react-dom/client/hydrateRoot',
77
+ } );
78
+
79
+ hydrateBase( element, container, callback );
80
+ }
81
+
82
+ /**
83
+ * Removes any mounted element from the target DOM node.
84
+ *
85
+ * @deprecated since WordPress 6.2.0. Use `root.unmount()` instead.
86
+ * @see https://react.dev/reference/react-dom/unmountComponentAtNode
87
+ *
88
+ * @param container DOM node in which to unmount.
89
+ * @return Whether the node was unmounted.
90
+ */
91
+ export function unmountComponentAtNode( container: Element ): boolean {
92
+ deprecated( 'wp.element.unmountComponentAtNode', {
93
+ since: '6.2',
94
+ alternative: 'root.unmount()',
95
+ link: 'https://react.dev/reference/react-dom/client/createRoot#root-unmount',
96
+ } );
97
+
98
+ return unmountComponentAtNodeBase( container );
99
+ }
@@ -0,0 +1,109 @@
1
+ import { act, render } from '@testing-library/react';
2
+ import { Component } from '..';
3
+ import { findDOMNode as findDOMNodePolyfill } from '../react-polyfill';
4
+
5
+ describe.skip( 'findDOMNode', () => {
6
+ it( 'should return null when passed null', () => {
7
+ expect( findDOMNodePolyfill( null ) ).toBeNull();
8
+ expect( console ).toHaveWarned();
9
+ } );
10
+
11
+ it( 'should return the element when passed a DOM element', () => {
12
+ const div = document.createElement( 'div' );
13
+ expect( findDOMNodePolyfill( div ) ).toBe( div );
14
+ } );
15
+
16
+ it( 'should track the current DOM node across re-renders', () => {
17
+ class Toggle extends Component {
18
+ constructor( props ) {
19
+ super( props );
20
+ this.state = { count: 0 };
21
+ this.results = [];
22
+ }
23
+
24
+ componentDidMount() {
25
+ this.recordNode();
26
+ }
27
+
28
+ componentDidUpdate() {
29
+ this.recordNode();
30
+ }
31
+
32
+ recordNode() {
33
+ const node = findDOMNodePolyfill( this );
34
+ this.results.push( node.tagName );
35
+ }
36
+
37
+ render() {
38
+ return this.state.count % 2 === 0 ? (
39
+ <div>even</div>
40
+ ) : (
41
+ <span>odd</span>
42
+ );
43
+ }
44
+ }
45
+
46
+ let toggleRef;
47
+ render( <Toggle ref={ ( ref ) => ( toggleRef = ref ) } /> );
48
+ act( () => toggleRef.setState( { count: 1 } ) );
49
+ act( () => toggleRef.setState( { count: 2 } ) );
50
+ act( () => toggleRef.setState( { count: 3 } ) );
51
+
52
+ expect( toggleRef.results ).toEqual( [ 'DIV', 'SPAN', 'DIV', 'SPAN' ] );
53
+ } );
54
+
55
+ it( 'should return null for an unmounted component', () => {
56
+ class MyComponent extends Component {
57
+ render() {
58
+ return <div>hello</div>;
59
+ }
60
+ }
61
+
62
+ let instanceRef;
63
+ const { rerender } = render(
64
+ <MyComponent
65
+ ref={ ( ref ) => {
66
+ instanceRef = ref;
67
+ return () => {};
68
+ } }
69
+ />
70
+ );
71
+
72
+ expect( findDOMNodePolyfill( instanceRef ) ).toBeInstanceOf(
73
+ window.HTMLDivElement
74
+ );
75
+
76
+ rerender( <p>replaced</p> );
77
+
78
+ expect( instanceRef ).not.toBeNull();
79
+ expect( findDOMNodePolyfill( instanceRef ) ).toBeNull();
80
+ } );
81
+
82
+ it( 'should find DOM node rendered by a nested child component', () => {
83
+ function Empty() {
84
+ return null;
85
+ }
86
+
87
+ function Inner() {
88
+ return <span className="inner">hello</span>;
89
+ }
90
+
91
+ class Outer extends Component {
92
+ render() {
93
+ return (
94
+ <>
95
+ <Empty />
96
+ <Inner />
97
+ </>
98
+ );
99
+ }
100
+ }
101
+
102
+ let outerRef;
103
+ render( <Outer ref={ ( ref ) => ( outerRef = ref ) } /> );
104
+
105
+ const node = findDOMNodePolyfill( outerRef );
106
+ expect( node ).toBeInstanceOf( window.HTMLSpanElement );
107
+ expect( node.className ).toBe( 'inner' );
108
+ } );
109
+ } );
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import { createElement } from '..';
5
+ import { render, hydrate, unmountComponentAtNode } from '../react-polyfill';
6
+
7
+ describe.skip( 'render', () => {
8
+ it( 'should render into a container', () => {
9
+ const container = document.createElement( 'div' );
10
+
11
+ render( createElement( 'p', null, 'hello' ), container );
12
+
13
+ expect( container ).toHaveTextContent( 'hello' );
14
+ expect( console ).toHaveWarned();
15
+ } );
16
+
17
+ it( 'should update the container on subsequent renders', () => {
18
+ const container = document.createElement( 'div' );
19
+
20
+ render( createElement( 'p', null, 'hello' ), container );
21
+ render( createElement( 'p', null, 'world' ), container );
22
+
23
+ expect( container ).toHaveTextContent( 'world' );
24
+ } );
25
+
26
+ it( 'should call the callback after rendering', () => {
27
+ const container = document.createElement( 'div' );
28
+ const callback = jest.fn();
29
+
30
+ render( createElement( 'p', null, 'hello' ), container, callback );
31
+
32
+ expect( callback ).toHaveBeenCalledTimes( 1 );
33
+ expect( container ).toHaveTextContent( 'hello' );
34
+ } );
35
+ } );
36
+
37
+ describe.skip( 'hydrate', () => {
38
+ it( 'should hydrate into a container with matching markup', () => {
39
+ const container = document.createElement( 'div' );
40
+ container.innerHTML = '<p>hello</p>';
41
+
42
+ hydrate( createElement( 'p', null, 'hello' ), container );
43
+
44
+ expect( container ).toHaveTextContent( 'hello' );
45
+ expect( console ).toHaveWarned();
46
+ } );
47
+
48
+ it( 'should call the callback after hydrating', () => {
49
+ const container = document.createElement( 'div' );
50
+ container.innerHTML = '<p>hello</p>';
51
+ const callback = jest.fn();
52
+
53
+ hydrate( createElement( 'p', null, 'hello' ), container, callback );
54
+
55
+ expect( callback ).toHaveBeenCalledTimes( 1 );
56
+ } );
57
+ } );
58
+
59
+ describe.skip( 'unmountComponentAtNode', () => {
60
+ it( 'should return false when the container has no root', () => {
61
+ const container = document.createElement( 'div' );
62
+
63
+ expect( unmountComponentAtNode( container ) ).toBe( false );
64
+ expect( console ).toHaveWarned();
65
+ } );
66
+
67
+ it( 'should unmount and return true when a root exists', () => {
68
+ const container = document.createElement( 'div' );
69
+
70
+ render( createElement( 'p', null, 'hello' ), container );
71
+ expect( container ).toHaveTextContent( 'hello' );
72
+
73
+ expect( unmountComponentAtNode( container ) ).toBe( true );
74
+ expect( container ).toHaveTextContent( '' );
75
+ expect( unmountComponentAtNode( container ) ).toBe( false );
76
+ } );
77
+ } );