Parity Checks (Native vs Decoupled)
How ForgeWP checks that one project gives the same result as a WordPress theme and as a separate Next.js app, how to run that check on your computer, and what to do when it fails.
ForgeWP can ship the same React project in two ways:
- Native: ForgeWP turns the project into a WordPress theme. WordPress itself shows the pages.
- Decoupled: the project runs as its own Next.js app, and reads its content from WordPress over the network.
Visitors should not be able to tell the difference. The same page should show the same text, the same menu and the same data either way. We call this parity, and a test called the parity check makes sure it stays true. It runs on GitHub for every pull request that changes the compiler or the runtime, so if you contribute to ForgeWP you will meet it sooner or later.
This page explains what the check does, how to run it yourself, and how to read a failure.
You don't need this to build themes
The parity check tests ForgeWP itself. If you only use ForgeWP to build your own site, you can skip this page.
1. What gets compared
The test project lives in projects/parity-fixture. It is deliberately small: a home page, an about page, a contact form, a blog with two posts, a category page and two pages that need a login. The check runs a set of smaller checks against it, one after the other:
Check What it makes sure of resourcesThe data WordPress puts in a native page ( window.forgeWpHydration.resources) is exactly what the matching REST address returns. The decoupled app reads that REST address, so both modes start from the same data.domText marked with a data-parity="…" attribute, and the links in the main menu, are the same on both versions of each page.leaksNo page contains leftovers from the build, such as __FORGEWP_…__ placeholders, <?php or a <forgewp-…> tag. Native pages must not load Next.js files (/_next/static).formThe contact form sends successfully in both modes and shows the same message. authA logged-out visitor who opens a page that needs a login ends up on the same address in both modes. localeThe page language ( <html lang>) and the translation data agree.commerceOnly when WooCommerce is installed: the cart, checkout and customer account addresses behave as described in the contract (guest carts, cart tokens, orders, refusing other customers' orders, and so on). |
|---|
Marking text for the `dom` check
The dom check only compares what you mark. If you add a new feature to the fixture and want it compared, put data-parity="some-name" on the element, for example <ul data-parity="posts">. Use a name that is unique on that page.
2. What the check does, step by step
The script scripts/parity/run.sh does everything for you:
- Starts WordPress. It runs WordPress, a MariaDB database and Mailpit (a fake mail inbox) in Docker, using
scripts/cloud-e2e/sandbox.sh. WithPARITY_WOOCOMMERCE=1it also installs WooCommerce and a small shop with a few products. - Builds the native version. It exports
projects/parity-fixtureas a theme, copies it into WordPress and activates it. It then adds some sample content: one comment, and a few stored values on the about page. - Waits for WordPress to be ready. It calls the ForgeWP REST addresses until each one answers with data, so the next step does not build pages from an empty answer.
- Builds the decoupled version. It runs
next buildandnext startfor the same project on port3100, pointed at the same WordPress. - Compares.
scripts/parity/run-parity.mjsopens both versions in a headless Chromium browser and runs the checks from the table above. - Checks the WordPress error log. Any PHP fatal error, parse error or warning, or any
[ForgeWP]warning inwp-content/debug.log, also fails the run, even if every comparison passed.
3. Run it on your computer
What you need
- Linux, or a Linux cloud machine. The script uses
sudoand Docker. It is not tested on macOS or Windows. - Docker installed and allowed to run.
- Node.js 22 and pnpm 10, with
pnpm installalready run at the root of the ForgeWP repository. - Chromium for Playwright. Install it once with:
pnpm --filter @forgewp/parity-fixture exec playwright install --with-deps chromiumRun the full check
From the root of the ForgeWP repository:
PARITY_RESET=1 PARITY_WOOCOMMERCE=1 scripts/parity/run.shThis is exactly what GitHub runs. The first run takes several minutes because Docker downloads WordPress and the script builds both versions. At the end you see one line per check and a summary:
▸ resources
122 passed, 0 failed
...
▸ commerce
23 passed, 0 failed
Parity: 173 passed, 0 failed, 0 known-gap differences
── WordPress debug.log
✓ debug.log cleanThe exact numbers change as checks are added. What matters is 0 failed and ✓ debug.log clean.
The settings you can change
All settings are environment variables. You put them before the command, as in the example above.
Setting What it does Default PARITY_RESET=1Deletes the WordPress database and files and starts from a fresh install. Use it when old content from an earlier run might change the result. Off: keep the running WordPress PARITY_WOOCOMMERCE=1Installs WooCommerce and the sample shop, and turns on the commerce check.Off FORGEWP_E2E_DATAThe folder where WordPress and the database keep their files. /home/user/e2ePARITY_REPORTWhere the JSON report is written. .forgewp/parity/report.jsonPARITY_NEXT_PORTThe port for the decoupled Next.js app. 3100 |
|---|
`PARITY_RESET=1` deletes that WordPress
Reset wipes the WordPress in the FORGEWP_E2E_DATA folder: every post, user and setting. It never touches LocalWP or any other site, but don't point FORGEWP_E2E_DATA at a folder you want to keep.
Run only some checks again
Building both versions is the slow part. When WordPress and the decoupled app are still running from a full run, you can repeat just the comparison, and only for the checks you care about:
node scripts/parity/run-parity.mjs --only dom,leaksYou can list any of resources, dom, leaks, form, auth, locale and commerce, separated by commas. Note that run.sh stops the Next.js app when it finishes, so start it again first if you need the dom, leaks or form checks. The commands are in step 4 of run.sh.
4. When the check fails
Each failure is printed under its check with the page it happened on and what was different:
▸ dom
✗ /about/ — native and decoupled DOM differ
$.parity.about-tagline: "Seeded tagline from WordPress" != "Default tagline"
6 passed, 1 failedRead it as: on /about/, the element marked data-parity="about-tagline" showed different text in the two versions. The value on the left of != comes from the native theme, the value on the right from the decoupled app.
Where to look next:
Failure in Usually means Look at resourcesThe PHP that prints data into native pages and the REST address disagree. packages/compiler/lib/functions/ and docs/resource-contracts.md in the ForgeWP repositorydomOne mode renders a component differently, or reads different data. The component in packages/react and how the compiler turns it into PHPleaksA placeholder was not replaced during export, or a component was not compiled. The compiler ( packages/compiler/lib/)commerceA shop address answers differently than the contract says. commerce-resources.js and contract §15debug.log WordPress logged a PHP error or warning. The lines printed above ✗ debug.log has PHP errors |
|---|
The report has more detail
Every run writes .forgewp/parity/report.json with every pass and failure. The same folder holds next-build.log, next.log, the WordPress debug.log and the web server log. On GitHub, download them from the run's parity-report artifact.
5. Known gaps
Sometimes a difference is real, already understood, and someone is working on it, but it should not block every other pull request in the meantime. Such a difference can be listed in scripts/parity/known-gaps.json. This example is a real entry from earlier in the project, since fixed:
1{
2 "gaps": [
3 {
4 "id": "R2-native-getposts-frozen",
5 "owner": "Who is fixing it",
6 "title": "getPosts() outside WpQueryLoop shows the build-time list in the native theme",
7 "check": "dom",
8 "routes": ["/listing/"],
9 "match": "\\$\\.parity\\.posts\\["
10 }
11 ]
12}A failure is treated as a known gap when its check matches check, its page is in routes (or routes is left out) and its message matches match, a regular expression (in JSON, each backslash is written twice). Known gaps are still printed, but they do not fail the run.
A gap that is fixed fails the run
If a listed gap no longer happens, the run fails with known gap … no longer reproduces. This is on purpose: it reminds you to delete the entry in the same pull request that fixes it, so the list only ever gets shorter. Today the list is empty, and we would like to keep it that way.
6. On GitHub
The workflow .github/workflows/parity.yml runs the full check (PARITY_RESET=1 PARITY_WOOCOMMERCE=1) on a fresh Linux machine:
- for every pull request that changes
packages/react,packages/compiler,projects/parity-fixture,scripts/parity,scripts/cloud-e2eorpnpm-lock.yaml, - for every push to
mainthat changes those same folders, - and whenever someone starts it by hand from the Actions tab (Parity (native vs decoupled), then Run workflow).
A pull request is ready to merge only when this workflow is green, together with the other checks.