Repository navigation
feat(du): support React 18.3 hosts in the DU widgets - #223
Open
sergiubologa wants to merge 3 commits into
Open
sergiubologa wants to merge 3 commits into
sergiubologa wants to merge 3 commits into
Conversation
React 18 sets a custom element's props as attributes, so the Document Viewer, Validation Station (and subcomponents) and Classification Station received `dom`, `options` and the references as "[object Object]". It also ignores a ref callback's returned cleanup, so listeners leaked and a persistent element was never force-destroyed. - WcHost renders the element: on React 19 unchanged; on React 18 it assigns the non-attribute props as properties in a layout effect, in key order. - useWcRef tears down on the null ref call, which both versions make. - Peer range react/react-dom ^18.3.0 || ^19.0.0 on all nine packages. - `npm run test:react18` runs the three DU suites against React 18 (test/react18), also in CI. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
📊 Coverage Report
|
… 18 path - React 18 writes `className` on a custom element as a `classname` attribute, so the host's class was lost; WcHost now passes it as `class`. - The inputs already assigned are tracked per element (WeakMap), so a ref that re-attaches to the same element does not re-assign unchanged inputs. - WcHost.test.tsx mocks React's version to run the React 18 path inside the normal (coverage) run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
When switching pre-fetched documents on React 18, removed inputs are cleared after the new documentId is assigned, violating initialization order and exposing the new document to stale inputs.
1 open issue
1 file not reviewed
test/react18/package-lock.json: Generated file
What changed in this PR
Adds React 18.3 support so Flow can use the Document Understanding widgets directly, while preserving React 19 support.
Changes:
- Adds version-aware web-component property assignment and ref teardown across the three DU packages.
- Expands React peer ranges across nine packages and updates compatibility documentation.
- Adds an isolated React 18 test runtime, regression tests, and CI coverage.
| File | Description |
|---|---|
| test/vitest.react18.ts | Aliases test dependencies to React 18. |
| test/react18/package.json | Defines the isolated React 18 runtime. |
| test/react18/package-lock.json | Locks React 18 runtime dependencies. |
| README.md | Updates supported React versions. |
| packages/validation-station/vitest.config.ts | Enables React 18 test overrides. |
| packages/validation-station/src/WcHost.tsx | Adds version-aware property assignment. |
| packages/validation-station/src/subcomponents/shared.ts | Routes subcomponent rendering through WcHost. |
| packages/validation-station/src/bindWcEvents.ts | Handles teardown through null refs. |
| packages/validation-station/src/__tests__/WcHost.test.tsx | Tests property assignment and ref forwarding. |
| packages/validation-station/src/__tests__/subcomponents.test.tsx | Supports input assertions on both React versions. |
| packages/validation-station/src/__tests__/shared.test.tsx | Updates rendering-helper assertions. |
| packages/validation-station/README.md | Documents React 18.3 compatibility. |
| packages/validation-station/package.json | Broadens React peer ranges. |
| packages/pdf-viewer/README.md | Documents React 18.3 compatibility. |
| packages/pdf-viewer/package.json | Broadens React peer ranges. |
| packages/multi-file-upload/README.md | Documents React 18.3 compatibility. |
| packages/multi-file-upload/package.json | Broadens React peer ranges. |
| packages/external-auth/README.md | Documents React 18.3 compatibility. |
| packages/external-auth/package.json | Broadens React peer ranges. |
| packages/document-viewer/vitest.config.ts | Enables React 18 test overrides. |
| packages/document-viewer/src/WcHost.tsx | Adds version-aware property assignment. |
| packages/document-viewer/src/renderWc.ts | Routes rendering through WcHost. |
| packages/document-viewer/src/bindWcEvents.ts | Handles teardown through null refs. |
| packages/document-viewer/src/__tests__/WcHost.test.tsx | Tests property assignment and ref forwarding. |
| packages/document-viewer/README.md | Documents React 18.3 compatibility. |
| packages/document-viewer/package.json | Broadens React peer ranges. |
| packages/decisions-and-reasons/package.json | Broadens React peer ranges. |
| packages/datatable/README.md | Documents React 18.3 compatibility. |
| packages/datatable/package.json | Broadens React peer ranges. |
| packages/conversational-agent-chat/README.md | Documents React 18.3 compatibility. |
| packages/conversational-agent-chat/package.json | Broadens React peer ranges. |
| packages/classification-station/vitest.config.ts | Enables React 18 test overrides. |
| packages/classification-station/src/WcHost.tsx | Adds version-aware property assignment. |
| packages/classification-station/src/renderWc.ts | Routes rendering through WcHost. |
| packages/classification-station/src/bindWcEvents.ts | Handles teardown through null refs. |
| packages/classification-station/src/__tests__/WcHost.test.tsx | Tests property assignment and ref forwarding. |
| packages/classification-station/README.md | Documents React 18.3 compatibility. |
| packages/classification-station/package.json | Broadens React peer ranges. |
| package.json | Adds the React 18 test command. |
| .github/workflows/test.yml | Runs DU tests against React 18 in CI. |
| .changeset/react-18-support.md | Records releases for compatibility changes. |
Review effort: Balanced
Classification Station needs documentId to arrive last. WcHost cleared a dropped input (pageUris, customizationInfo) only after assigning the new documentId, so a document switch could reach the element with the previous document's input still set. Clear removed inputs first, as React 19 does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.

Why
Flow is on React 18.3 and wants to use the DU widgets directly instead of its own wrapper. Two things broke on React 18:
renderWcElementpassed every input throughcreateElement(tag, props). React 19 assigns those as element properties; React 18 assigns them as attributes, sodom,options,text, the references and the rest reached the element as"[object Object]".useWcRefreturned a cleanup from the ref callback. React 18 ignores that return value and calls the ref withnullinstead, which the callback skipped.What changed
WcHost.tsx(one per DU package: document-viewer, validation-station, classification-station) renders the element.className(passed asclass, since React 18 would write it as aclassnameattribute),styleand dashed names (instance-id) go on the tag. The other inputs are assigned as properties in a layout effect, inpropskey order (CS relies ondocumentIdcoming last), before paint. Only changed values are assigned, tracked per element. A removed input goes back toundefined.useWcReftears down (unbind, plusforceDestroy()when persistent) on thenullref call, which both versions make.react/react-dom^18.3.0 || ^19.0.0on all nine packages. The non-DU packages use no React-19-only APIs, and their dependencies (apollo-react, apollo-wind, ag-grid-react, react-pdf, react-i18next) all accept 18. READMEs and a changeset updated.npm run test:react18runs the three DU suites against React 18, also added as a CI step intest.yml. React 18 lives intest/react18with its own lockfile, because npm won't let React 18 and 19 share the workspace dependency tree.test/vitest.react18.tsaliasesreact/react-domto it and loads Testing Library's ESM build so it uses the same copy.WcHost.test.tsxmocks React'sversionso the React 18 path also runs (and counts) in the normal coverage run.Verification
forceDestroy.artifacts:loaded/dirtyevents.CompactFieldsFormwith the VSDocumentViewer, linked throughinstance-id.dirty/hasChangesevents.[object Object]attributes: none appeared, and object inputs arrived as objects.react/compiler-runtime, which React 18 doesn't have.🤖 Generated with Claude Code