Skip to content

Expose React and ReactDOM globally for SENAITE add-ons#2961

Open
ramonski wants to merge 1 commit into
2.xfrom
2.x-expose-react
Open

Expose React and ReactDOM globally for SENAITE add-ons#2961
ramonski wants to merge 1 commit into
2.xfrom
2.x-expose-react

Conversation

@ramonski

@ramonski ramonski commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Description of the issue/feature this PR addresses

Expose a single, shared React instance so SENAITE add-ons and standalone views can consume React via Webpack externals instead of bundling their own copy. This is the provider half required by the senaite.app.spotlight React rewrite (and any future React add-on).

React is shipped as a dedicated, stable-named vendor-react.js bundle and loaded as a plain <script> (in resources.pt), exactly like the vendored jQuery and TinyMCE libraries. senaite.core itself now consumes React through externals as well, so React is loaded only once on the page.

Current behavior before PR

senaite.core bundles React privately inside its main bundle and never exposes it. An add-on that wants React must bundle its own copy, which loads a second React instance on the page (breaking shared hooks/context) and inflates the add-on bundle. Standalone views that do not include the core resources (e.g. senaite.impress publish views) have no access to a shared React at all.

Desired behavior after PR is merged

A standalone modules/react/vendor-react.js assigns window.React and a merged window.ReactDOM (react-dom + react-dom/client, so both createRoot and createPortal resolve). senaite.core consumes react, react-dom and react-dom/client via externals, and any add-on or standalone view does the same — including just the one vendor-react.js script tag when it does not pull in the core resources. The core bundle no longer contains React, so it is smaller and React is cached independently of the core bundle hash.

Assign window.React and window.ReactDOM via a dedicated vendor-react bundle
loaded as a plain <script> (like the vendored jQuery/TinyMCE), and consume
react/react-dom as Webpack externals in core, so SENAITE add-ons and
standalone views can share a single React instance. Rebuilt the bundles.
@ramonski ramonski requested a review from xispa June 23, 2026 12:58
@ramonski ramonski added the Webpack 📦 Static module bundler updates label Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Webpack 📦 Static module bundler updates

Development

Successfully merging this pull request may close these issues.

1 participant