@planningcenter/sweetest-alert 2.0.0 → 2.0.2

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.
Files changed (2) hide show
  1. package/README.md +42 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -24,6 +24,48 @@ This package requires the following peer dependencies:
24
24
  - `@planningcenter/tapestry` >=4
25
25
  - `@planningcenter/icons` ^15.29.1
26
26
 
27
+ ### Using with React 17
28
+
29
+ The peer dependency range is `react`/`react-dom` `^18.3.1 || ^19.0.0` because sweetest-alert statically imports `createRoot` from `react-dom/client`, which doesn't exist on React 17. If your app is still on React 17 (as `giving` was — see [planningcenter/giving#8757](https://github.com/planningcenter/giving/pull/8757)), you can't upgrade react-dom just for this package, but you can shim the import your bundler resolves instead of the real module.
30
+
31
+ Add a shim implementing the subset of the `react-dom/client` API sweetest-alert actually uses (`createRoot(container).render()`/`.unmount()`), backed by React 17's real APIs:
32
+
33
+ ```js
34
+ // app/javascript/utils/react_dom_client_shim.js
35
+ import ReactDOM from "react-dom"
36
+
37
+ // react-dom/client doesn't exist on React 17. sweetest-alert statically
38
+ // imports createRoot from it, which fails at build time otherwise. This
39
+ // shim implements just the subset it actually uses so the import resolves
40
+ // and behaves the same as it would on React 18. Remove once on React 18
41
+ // and this can be dropped in favor of the real react-dom/client.
42
+ export function createRoot(container) {
43
+ return {
44
+ render: (element) => {
45
+ ReactDOM.render(element, container)
46
+ },
47
+ unmount: () => ReactDOM.unmountComponentAtNode(container),
48
+ }
49
+ }
50
+ ```
51
+
52
+ Then alias `react-dom/client` to it in your bundler config. For Vite:
53
+
54
+ ```js
55
+ // vite.config.mjs
56
+ resolve: {
57
+ alias: [
58
+ // ...your other aliases,
59
+ {
60
+ find: "react-dom/client",
61
+ replacement: resolve(__dirname, "app/javascript/utils/react_dom_client_shim.js"),
62
+ },
63
+ ],
64
+ },
65
+ ```
66
+
67
+ If you also run tests through Vitest, add the same alias to its config (or to whatever `resolve.alias` it merges from your Vite config) so component tests resolve the shim too.
68
+
27
69
  ## Usage
28
70
 
29
71
  ### Basic Example
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@planningcenter/sweetest-alert",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "The sweetest alert ever",
5
5
  "type": "module",
6
6
  "packageManager": "yarn@4.14.1+sha512.64df448055b2d37ba269d7db535a469b8da93f8ef1140c25fd7a83c00a8fbaacb214ca0e02553b92a2c54cef78bb67d0b4817fab02001df0e24fac0faccc3b42",