@seamlessdocs/payment-modals 2.0.0-beta.3 → 2.0.0-beta.5
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/build/payment-modals.js +1 -1
- package/package.json +1 -1
- package/src/index.jsx +41 -2
- package/webpack.config.js +6 -0
package/package.json
CHANGED
package/src/index.jsx
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { createRoot } from 'react-dom/client';
|
|
2
|
-
|
|
3
1
|
import ChooseModal from './Components/ChooseModal';
|
|
4
2
|
import ProcessingModal from './Components/ProcessingModal';
|
|
5
3
|
import ErrorModal from './Components/ErrorModal';
|
|
@@ -19,6 +17,46 @@ import './OpenViewStyles.css';
|
|
|
19
17
|
// Store root instances to manage React 18 roots
|
|
20
18
|
const rootInstances = new Map();
|
|
21
19
|
|
|
20
|
+
// Helper function to get createRoot - handles both bundled (dev) and external (prod) scenarios
|
|
21
|
+
const getCreateRoot = () => {
|
|
22
|
+
// Strategy 1: Access ReactDOM from global scope FIRST (works in production with externals)
|
|
23
|
+
// This is the primary method for production builds where react-dom is external
|
|
24
|
+
const ReactDOM = (typeof window !== 'undefined' && window.ReactDOM)
|
|
25
|
+
|| (typeof global !== 'undefined' && global.ReactDOM)
|
|
26
|
+
|| (typeof self !== 'undefined' && self.ReactDOM);
|
|
27
|
+
|
|
28
|
+
if (ReactDOM && typeof ReactDOM.createRoot === 'function') {
|
|
29
|
+
return ReactDOM.createRoot;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Strategy 2: Try to require react-dom/client directly (works in development only)
|
|
33
|
+
// Only use this in development when react-dom is bundled
|
|
34
|
+
try {
|
|
35
|
+
const reactDomClient = require('react-dom/client');
|
|
36
|
+
if (reactDomClient && reactDomClient.createRoot && typeof reactDomClient.createRoot === 'function') {
|
|
37
|
+
return reactDomClient.createRoot;
|
|
38
|
+
}
|
|
39
|
+
} catch (e) {
|
|
40
|
+
// Ignore require errors - module might not be available (especially in production)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Strategy 3: Try to require react-dom and access createRoot (works in development only)
|
|
44
|
+
try {
|
|
45
|
+
const ReactDOMModule = require('react-dom');
|
|
46
|
+
if (ReactDOMModule && typeof ReactDOMModule.createRoot === 'function') {
|
|
47
|
+
return ReactDOMModule.createRoot;
|
|
48
|
+
}
|
|
49
|
+
} catch (e) {
|
|
50
|
+
// Ignore require errors
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
throw new Error(
|
|
54
|
+
'createRoot is not available. Make sure React 18 is loaded. ' +
|
|
55
|
+
'In development, react-dom should be bundled. ' +
|
|
56
|
+
'In production, ReactDOM should be available globally as window.ReactDOM.'
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
|
|
22
60
|
// Helper function to render with React 18 createRoot
|
|
23
61
|
const renderModal = (element, containerId) => {
|
|
24
62
|
const containerElement = document.getElementById(containerId);
|
|
@@ -30,6 +68,7 @@ const renderModal = (element, containerId) => {
|
|
|
30
68
|
// Get or create root instance
|
|
31
69
|
let root = rootInstances.get(containerId);
|
|
32
70
|
if (!root) {
|
|
71
|
+
const createRoot = getCreateRoot();
|
|
33
72
|
root = createRoot(containerElement);
|
|
34
73
|
rootInstances.set(containerId, root);
|
|
35
74
|
}
|
package/webpack.config.js
CHANGED