Skip to content

(feat): make react and react-dom external#54

Merged
YvetteNikolov merged 1 commit into
mainfrom
fix/reactive-search
Sep 12, 2025
Merged

(feat): make react and react-dom external#54
YvetteNikolov merged 1 commit into
mainfrom
fix/reactive-search

Conversation

@YvetteNikolov
Copy link
Copy Markdown
Contributor

Dit zorgt ervoor dat react en react-dom niet meegebundeld worden, maar gebruik maken van de globale versies die WordPress via wp-element aanbiedt (via window.React en window.ReactDOM). Net zoals @wordpress/scripts het doet.

Om React en ReactDOM beschikbaar te maken in de frontend, moet je wp_enqueue_script('wp-element'); gebruiken.

@YvetteNikolov YvetteNikolov requested review from a team, FreakyWizard, JasperS20, WybeBosch, Yannicvanveen, hnccox-yard, laravdiemen and rivanuff and removed request for a team September 12, 2025 07:32
@WybeBosch WybeBosch requested a review from Copilot September 12, 2025 07:37
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds React and ReactDOM externalization to the Vite configuration to prevent bundling these libraries by referencing WordPress's global versions available through wp-element.

  • Integrates vite-plugin-externals to externalize React dependencies
  • Maps react and react-dom to global window.React and window.ReactDOM
  • Adds vite-plugin-externals as a new dependency

Reviewed Changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/vite-config/src/configs/brave.js Adds externals plugin configuration to reference global React instances
packages/vite-config/package.json Adds vite-plugin-externals dependency

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +111 to +113
viteExternalsPlugin( {
react: 'React',
'react-dom': 'ReactDOM',
Copy link

Copilot AI Sep 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The external mapping assumes WordPress provides React and ReactDOM at window.React and window.ReactDOM, but WordPress wp-element actually provides them at window.wp.element.Component and window.wp.element.render. You should verify the correct global variable names or add runtime checks to ensure compatibility.

Suggested change
viteExternalsPlugin( {
react: 'React',
'react-dom': 'ReactDOM',
// Map React and ReactDOM to WordPress' wp.element global to avoid duplicate React instances.
viteExternalsPlugin( {
react: 'wp.element',
'react-dom': 'wp.element',

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

volgens mij praat hij poep

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💩

Copy link
Copy Markdown
Contributor

@WybeBosch WybeBosch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Goed bezuggg yvettje.
handig dat de viteExternalsPlugin alle react imports veranderd naar de window nu ! :D

@YvetteNikolov YvetteNikolov merged commit 28d76ca into main Sep 12, 2025
1 check passed
@YvetteNikolov YvetteNikolov deleted the fix/reactive-search branch September 12, 2025 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants