Skip to content

Commit c02ae43

Browse files
committed
feature symfony#3314 [React] Add support for React 19 (Kocal)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- [React] Add support for React 19 | Q | A | -------------- | --- | Bug fix? | no | New feature? | yes <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- if yes, also update UPGRADE-*.md and src/**/CHANGELOG.md --> | Documentation? | no <!-- required for new features, or documentation updates --> | Issues | Fix symfony#3313 <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT <!-- Replace this notice by a description of your feature/bugfix. This will help reviewers and should be a good start for the documentation. Additionally (see https://symfony.com/releases): - Always add tests and ensure they pass. - For new features, provide some code snippets to help understand usage. - Features and deprecations must be submitted against branch main. - Update/add documentation as required (we can help!) - Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry - Never break backward compatibility (see https://symfony.com/bc). --> Commits ------- 2a873b9 [React] Add support for React 19
2 parents 7dcc1fc + 2a873b9 commit c02ae43

File tree

4 files changed

+101
-33
lines changed

4 files changed

+101
-33
lines changed

bin/unit_test_package.sh

Lines changed: 79 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22

33
# This script is used to unit test assets from an UX package.
44
# It also handle the case where a package has multiple versions of a peerDependency defined.
5+
#
6+
# You can configure which peer dependency versions to test by adding a "config.tests.peerDependencyVersions"
7+
# field in your package.json. Example:
8+
#
9+
# "config": {
10+
# "tests": {
11+
# "peerDependencyVersions": [
12+
# { "react": "^18.0", "react-dom": "^18.0" },
13+
# { "react": "^19.0", "react-dom": "^19.0" }
14+
# ]
15+
# }
16+
# }
17+
#
18+
# If no configuration is provided, the script will fall back to testing each peerDependency
19+
# with multiple versions (||) independently.
520

621
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
722
PROJECT_DIR=$(dirname "$SCRIPT_DIR")
@@ -36,6 +51,36 @@ runTestSuite() {
3651
(cd "$location"; pnpm exec vitest --run "${args[@]}") || { all_tests_passed=false; }
3752
}
3853

54+
# Process peer dependency versions from explicit configuration
55+
processConfiguredVersions() {
56+
local config_length
57+
config_length=$(jq '.config.tests.peerDependencyVersions | length' "$package_json_path")
58+
59+
echo " -> Found $config_length configured peer dependency version set(s)"
60+
61+
for ((i=0; i<config_length; i++)); do
62+
echo -e "\n📦 Processing version set $((i+1))/$config_length..."
63+
64+
# Get all packages and versions for this configuration set
65+
install_args=""
66+
description=""
67+
while IFS="=" read -r pkg version; do
68+
install_args="$install_args $pkg@$version"
69+
description="$description $pkg@$version"
70+
done < <(jq -r ".config.tests.peerDependencyVersions[$i] | to_entries[] | \"\(.key)=\(.value)\"" "$package_json_path")
71+
72+
echo -e " - Installing$description for $workspace\n"
73+
(cd "$location" || exit 1; pnpm add $install_args --save-peer --silent)
74+
echo -e " - Building $workspace assets...\n"
75+
(cd "$location" || exit 1; pnpm run build)
76+
77+
runTestSuite
78+
done
79+
80+
echo -e "\n -> Reverting changes"
81+
git checkout -- "$package_json_path" "$location/dist" "$PROJECT_DIR/pnpm-lock.yaml"
82+
}
83+
3984
processWorkspace() {
4085
if [ ! -d "$location" ]; then
4186
echo "⚠ No directory found at $location"
@@ -56,35 +101,44 @@ processWorkspace() {
56101

57102
echo -e "⏳ Processing workspace $workspace at location $location...\n"
58103

59-
echo "⚙️ Checking '$package_json_path' for peerDependencies with multiple versions defined"
60-
deps_with_multiple_versions=$(jq -r '.peerDependencies | to_entries[] | select(.value | contains("||")) | .key' "$package_json_path")
61-
62-
if [ -n "$deps_with_multiple_versions" ]; then
63-
echo " -> Multiple versions found for peerDependencies: $deps_with_multiple_versions"
64-
for library in $deps_with_multiple_versions; do
65-
versionValue=$(jq -r ".peerDependencies.\"$library\"" "$package_json_path")
66-
67-
IFS="||" read -ra versions <<< "$versionValue"
104+
echo "⚙️ Checking '$package_json_path' for peer dependency test configuration"
68105

69-
for version in "${versions[@]}"; do
70-
trimmed_version=$(echo "$version" | tr -d '[:space:]')
71-
if [ -n "$trimmed_version" ]; then
72-
# Install each version of the library separately
73-
echo -e " - Installing $library@$trimmed_version for $workspace\n"
74-
(cd "$location" || exit 1; pnpm add "$library@$trimmed_version" --save-peer --silent)
75-
echo -e " - Building $workspace assets...\n"
76-
(cd "$location" || exit 1; pnpm run build)
106+
# Check if explicit configuration exists
107+
has_config=$(jq 'if has("config") and .config != null and (.config | has("tests")) and .config.tests != null and (.config.tests | has("peerDependencyVersions")) then true else false end' "$package_json_path")
77108

78-
runTestSuite
79-
fi
109+
if [ "$has_config" = "true" ]; then
110+
processConfiguredVersions
111+
else
112+
# Fallback: process peer dependencies with multiple versions (||) independently
113+
deps_with_multiple_versions=$(jq -r '.peerDependencies | to_entries[] | select(.value | contains("||")) | .key' "$package_json_path")
114+
115+
if [ -n "$deps_with_multiple_versions" ]; then
116+
echo " -> Multiple versions found for peerDependencies: $deps_with_multiple_versions"
117+
for library in $deps_with_multiple_versions; do
118+
versionValue=$(jq -r ".peerDependencies.\"$library\"" "$package_json_path")
119+
120+
IFS="||" read -ra versions <<< "$versionValue"
121+
122+
for version in "${versions[@]}"; do
123+
trimmed_version=$(echo "$version" | tr -d '[:space:]')
124+
if [ -n "$trimmed_version" ]; then
125+
# Install each version of the library separately
126+
echo -e " - Installing $library@$trimmed_version for $workspace\n"
127+
(cd "$location" || exit 1; pnpm add "$library@$trimmed_version" --save-peer --silent)
128+
echo -e " - Building $workspace assets...\n"
129+
(cd "$location" || exit 1; pnpm run build)
130+
131+
runTestSuite
132+
fi
133+
done
80134
done
81-
done
82135

83-
echo " -> Reverting changes"
84-
git checkout -- "$package_json_path" "$location/dist" "$PROJECT_DIR/pnpm-lock.yaml"
85-
else
86-
echo -e " -> No peerDependencies found with multiple versions defined\n"
87-
runTestSuite
136+
echo " -> Reverting changes"
137+
git checkout -- "$package_json_path" "$location/dist" "$PROJECT_DIR/pnpm-lock.yaml"
138+
else
139+
echo -e " -> No peerDependencies found with multiple versions defined\n"
140+
runTestSuite
141+
fi
88142
fi
89143
}
90144

pnpm-lock.yaml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/React/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# CHANGELOG
22

3+
## 2.33
4+
5+
- Add support for React 19.
6+
7+
Dependencies `react` and `react-dom` need to be updated together to version `^19.0` if you want to use React 19.
8+
39
## 2.30
410

511
- Ensure compatibility with PHP 8.5

src/React/assets/package.json

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414
],
1515
"main": "dist/register_controller.js",
1616
"types": "dist/register_controller.d.ts",
17+
"config": {
18+
"tests": {
19+
"peerDependencyVersions": [
20+
{ "react": "^18.0", "react-dom": "^18.0" },
21+
{ "react": "^19.0", "react-dom": "^19.0" }
22+
]
23+
}
24+
},
1725
"scripts": {
1826
"build": "tsx ../../../bin/build_package.ts .",
1927
"watch": "tsx ../../../bin/build_package.ts . --watch",
@@ -35,23 +43,23 @@
3543
},
3644
"importmap": {
3745
"@hotwired/stimulus": "^3.0.0",
38-
"react": "^18.0",
39-
"react-dom/client": "^18.0",
46+
"react": "^18.0 || ^19.0",
47+
"react-dom/client": "^18.0 || ^19.0",
4048
"@symfony/ux-react": "path:%PACKAGE%/dist/loader.js"
4149
}
4250
},
4351
"peerDependencies": {
4452
"@hotwired/stimulus": "^3.0.0",
45-
"react": "^18.0",
46-
"react-dom": "^18.0"
53+
"react": "^18.0 || ^19.0",
54+
"react-dom": "^18.0 || ^19.0"
4755
},
4856
"devDependencies": {
4957
"@hotwired/stimulus": "^3.0.0",
5058
"@testing-library/dom": "^10.4.0",
5159
"@testing-library/jest-dom": "^6.6.3",
5260
"@testing-library/user-event": "^14.6.1",
53-
"@types/react": "^18.0",
54-
"@types/react-dom": "^18.0",
61+
"@types/react": "^18.0 || ^19.0",
62+
"@types/react-dom": "^18.0 || ^19.0",
5563
"@types/webpack-env": "^1.16",
5664
"@vitejs/plugin-react": "^4.1.0",
5765
"jsdom": "^26.1.0",

0 commit comments

Comments
 (0)