@seamlessdocs/payment-modals 2.0.0-beta.6 → 2.0.0-beta.7

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.6",
3
+ "version": "2.0.0-beta.7",
4
4
  "description": "Payment modals for SeamlessDocs",
5
5
  "main": "build/payment-modals.js",
6
6
  "repository": {
package/src/index.jsx CHANGED
@@ -1,3 +1,8 @@
1
+ // Import createRoot - webpack will handle externals correctly
2
+ // In development: will be bundled from react-dom/client
3
+ // In production: will be external and resolved to ReactDOM global
4
+ import * as ReactDOMClient from 'react-dom/client';
5
+
1
6
  import ChooseModal from './Components/ChooseModal';
2
7
  import ProcessingModal from './Components/ProcessingModal';
3
8
  import ErrorModal from './Components/ErrorModal';
@@ -17,10 +22,29 @@ import './OpenViewStyles.css';
17
22
  // Store root instances to manage React 18 roots
18
23
  const rootInstances = new Map();
19
24
 
20
- // Helper function to get createRoot - handles both bundled (dev) and external (prod) scenarios
25
+ // Helper function to get createRoot - works in both development and production
21
26
  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
27
+ // Strategy 1: Try the imported module first (works in development when bundled)
28
+ // Check if createRoot is available directly or as a property
29
+ let createRootFn = null;
30
+
31
+ if (ReactDOMClient) {
32
+ // Try direct access
33
+ if (typeof ReactDOMClient.createRoot === 'function') {
34
+ createRootFn = ReactDOMClient.createRoot;
35
+ }
36
+ // Try as default export property
37
+ else if (ReactDOMClient.default && typeof ReactDOMClient.default.createRoot === 'function') {
38
+ createRootFn = ReactDOMClient.default.createRoot;
39
+ }
40
+ }
41
+
42
+ if (createRootFn) {
43
+ return createRootFn;
44
+ }
45
+
46
+ // Strategy 2: Access ReactDOM from global scope (works in production with externals)
47
+ // Also works in development if React is loaded globally
24
48
  const ReactDOM = (typeof window !== 'undefined' && window.ReactDOM)
25
49
  || (typeof global !== 'undefined' && global.ReactDOM)
26
50
  || (typeof self !== 'undefined' && self.ReactDOM);
@@ -29,27 +53,6 @@ const getCreateRoot = () => {
29
53
  return ReactDOM.createRoot;
30
54
  }
31
55
 
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
56
  throw new Error(
54
57
  'createRoot is not available. Make sure React 18 is loaded. ' +
55
58
  'In development, react-dom should be bundled. ' +