|
1 | | -import React from 'react'; |
2 | 1 | import ReactDOM from 'react-dom'; |
| 2 | +import { createRoot } from 'react-dom/client'; |
3 | 3 | import enMessages from '../app/translations/en.json'; |
4 | 4 |
|
5 | | -// React 19 compatibility shim for unmountComponentAtNode |
| 5 | +// React 19 compatibility: Patch missing ReactDOM methods |
6 | 6 | if (!ReactDOM.unmountComponentAtNode) { |
7 | | - ReactDOM.unmountComponentAtNode = (container) => { |
8 | | - if (container._reactRootContainer) { |
| 7 | + ReactDOM.unmountComponentAtNode = function(container) { |
| 8 | + if (container && container._reactInternalInstance) { |
| 9 | + // For older React versions compatibility |
| 10 | + container._reactInternalInstance.unmount(); |
| 11 | + delete container._reactInternalInstance; |
| 12 | + return true; |
| 13 | + } |
| 14 | + |
| 15 | + if (container && container._reactRootContainer) { |
9 | 16 | container._reactRootContainer.unmount(); |
10 | 17 | delete container._reactRootContainer; |
11 | 18 | return true; |
12 | 19 | } |
| 20 | + |
| 21 | + // Fallback: clean the container |
| 22 | + if (container) { |
| 23 | + while (container.firstChild) { |
| 24 | + container.removeChild(container.firstChild); |
| 25 | + } |
| 26 | + return true; |
| 27 | + } |
| 28 | + |
13 | 29 | return false; |
14 | 30 | }; |
15 | 31 | } |
16 | 32 |
|
| 33 | +if (!ReactDOM.render) { |
| 34 | + ReactDOM.render = function(element, container, callback) { |
| 35 | + let root = container._reactRootContainer; |
| 36 | + if (!root) { |
| 37 | + root = container._reactRootContainer = createRoot(container); |
| 38 | + } |
| 39 | + |
| 40 | + root.render(element); |
| 41 | + |
| 42 | + if (callback) { |
| 43 | + setTimeout(callback, 0); |
| 44 | + } |
| 45 | + }; |
| 46 | +} |
| 47 | + |
17 | 48 | export const parameters = { |
18 | 49 | actions: { argTypesRegex: '^on[A-Z].*' }, |
19 | 50 | controls: { |
|
0 commit comments