@seamlessdocs/payment-modals 2.0.0-beta.3 → 2.0.0-beta.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seamlessdocs/payment-modals",
3
- "version": "2.0.0-beta.3",
3
+ "version": "2.0.0-beta.4",
4
4
  "description": "Payment modals for SeamlessDocs",
5
5
  "main": "build/payment-modals.js",
6
6
  "repository": {
package/src/index.jsx CHANGED
@@ -1,4 +1,7 @@
1
- import { createRoot } from 'react-dom/client';
1
+ // Import createRoot - webpack will handle this correctly:
2
+ // - In development: bundled from react-dom/client
3
+ // - In production: external, resolved to ReactDOM global via webpack externals
4
+ import { createRoot as createRootFromModule } from 'react-dom/client';
2
5
 
3
6
  import ChooseModal from './Components/ChooseModal';
4
7
  import ProcessingModal from './Components/ProcessingModal';
@@ -19,6 +22,50 @@ import './OpenViewStyles.css';
19
22
  // Store root instances to manage React 18 roots
20
23
  const rootInstances = new Map();
21
24
 
25
+ // Helper function to get createRoot - handles both bundled (dev) and external (prod) scenarios
26
+ const getCreateRoot = () => {
27
+ // Strategy 1: Try the imported module (works in development when bundled)
28
+ if (createRootFromModule && typeof createRootFromModule === 'function') {
29
+ return createRootFromModule;
30
+ }
31
+
32
+ // Strategy 2: Try to require react-dom/client directly (works in development)
33
+ try {
34
+ const reactDomClient = require('react-dom/client');
35
+ if (reactDomClient && reactDomClient.createRoot && typeof reactDomClient.createRoot === 'function') {
36
+ return reactDomClient.createRoot;
37
+ }
38
+ } catch (e) {
39
+ // Ignore require errors - module might not be available
40
+ }
41
+
42
+ // Strategy 3: Try to require react-dom and access createRoot (works in development)
43
+ try {
44
+ const ReactDOM = require('react-dom');
45
+ if (ReactDOM && typeof ReactDOM.createRoot === 'function') {
46
+ return ReactDOM.createRoot;
47
+ }
48
+ } catch (e) {
49
+ // Ignore require errors
50
+ }
51
+
52
+ // Strategy 4: Access ReactDOM from global scope (works in production with externals)
53
+ // Also works in development if React is loaded globally
54
+ const ReactDOM = (typeof window !== 'undefined' && window.ReactDOM)
55
+ || (typeof global !== 'undefined' && global.ReactDOM)
56
+ || (typeof self !== 'undefined' && self.ReactDOM);
57
+
58
+ if (ReactDOM && typeof ReactDOM.createRoot === 'function') {
59
+ return ReactDOM.createRoot;
60
+ }
61
+
62
+ throw new Error(
63
+ 'createRoot is not available. Make sure React 18 is loaded. ' +
64
+ 'In development, react-dom should be bundled. ' +
65
+ 'In production, ReactDOM should be available globally.'
66
+ );
67
+ };
68
+
22
69
  // Helper function to render with React 18 createRoot
23
70
  const renderModal = (element, containerId) => {
24
71
  const containerElement = document.getElementById(containerId);
@@ -30,6 +77,7 @@ const renderModal = (element, containerId) => {
30
77
  // Get or create root instance
31
78
  let root = rootInstances.get(containerId);
32
79
  if (!root) {
80
+ const createRoot = getCreateRoot();
33
81
  root = createRoot(containerElement);
34
82
  rootInstances.set(containerId, root);
35
83
  }
package/webpack.config.js CHANGED
@@ -34,6 +34,12 @@ module.exports = (_env, argv) => {
34
34
  amd: 'react-dom',
35
35
  root: 'ReactDOM'
36
36
  },
37
+ 'react-dom/client': {
38
+ commonjs: 'react-dom',
39
+ commonjs2: 'react-dom',
40
+ amd: 'react-dom',
41
+ root: 'ReactDOM'
42
+ }
37
43
  } : {},
38
44
  module: {
39
45
  rules: [