Expose React and ReactDOM globally for SENAITE add-ons#2961
Open
ramonski wants to merge 1 commit into
Open
Conversation
bbe7c9e to
3002d6d
Compare
3002d6d to
8f3d62a
Compare
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.
8f3d62a to
0fa0546
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.jsbundle and loaded as a plain<script>(inresources.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.jsassignswindow.Reactand a mergedwindow.ReactDOM(react-dom + react-dom/client, so bothcreateRootandcreatePortalresolve). senaite.core consumesreact,react-domandreact-dom/clientvia externals, and any add-on or standalone view does the same — including just the onevendor-react.jsscript 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.