Skip to content

feat(du): support React 18.3 hosts in the DU widgets - #223

Open
sergiubologa wants to merge 3 commits into
developfrom
feat/react-18-support
Open

sergiubologa wants to merge 3 commits into
developfrom
feat/react-18-support

Conversation

@sergiubologa

@sergiubologa sergiubologa commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

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:

  1. Inputs arrived as strings. renderWcElement passed every input through createElement(tag, props). React 19 assigns those as element properties; React 18 assigns them as attributes, so dom, options, text, the references and the rest reached the element as "[object Object]".
  2. Listeners leaked and persistent elements were never torn down. useWcRef returned a cleanup from the ref callback. React 18 ignores that return value and calls the ref with null instead, which the callback skipped.

What changed

  • WcHost.tsx (one per DU package: document-viewer, validation-station, classification-station) renders the element.
    • React 19: unchanged. Every prop goes on the tag and React assigns it as a property before the element connects.
    • React 18: only className (passed as class, since React 18 would write it as a classname attribute), style and dashed names (instance-id) go on the tag. The other inputs are assigned as properties in a layout effect, in props key order (CS relies on documentId coming last), before paint. Only changed values are assigned, tracked per element. A removed input goes back to undefined.
  • useWcRef tears down (unbind, plus forceDestroy() when persistent) on the null ref call, which both versions make.
  • Peer range react / react-dom ^18.3.0 || ^19.0.0 on 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:react18 runs the three DU suites against React 18, also added as a CI step in test.yml. React 18 lives in test/react18 with its own lockfile, because npm won't let React 18 and 19 share the workspace dependency tree. test/vitest.react18.ts aliases react / react-dom to it and loads Testing Library's ESM build so it uses the same copy.
  • WcHost.test.tsx mocks React's version so the React 18 path also runs (and counts) in the normal coverage run.
  • The VS subcomponent tests read string inputs either as properties or as attributes. With the stub elements, React 19 sets undeclared inputs as attributes, while the React 18 path sets them as properties.

Verification

  • Unit tests: all DV, VS and CS tests pass on React 19 and on React 18 (39 / 317 / 55). Typecheck, lint and build are clean.
  • The React 18 run catches both bugs: with the old helpers restored, 4 Document Viewer tests fail on property assignment and forceDestroy.
  • Real web components on React 18.3.1: rendered with the DU-App invoice and CS fixtures as pre-fetched artifacts:
    • Full Validation Station: fields, highlights, and the loaded / dirty events.
    • CompactFieldsForm with the VS DocumentViewer, linked through instance-id.
    • Standalone Document Viewer.
    • Classification Station: both document-type groups, 10-page viewer, and the dirty / hasChanges events.
  • No [object Object] attributes: none appeared, and object inputs arrived as objects.
  • React 19: the same page on React 19 still loads Validation Station.
  • Storybook was not used for the React 18 check: it pre-bundles its own React, and the root Vite config's React Compiler needs react/compiler-runtime, which React 18 doesn't have.

🤖 Generated with Claude Code

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>
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

📊 Coverage Report

Package Line Coverage
datatable 88.29%
multi-file-upload 87.27%
conversational-agent-chat 91.63%
validation-station 99.38%
classification-station 93.12%
document-viewer 91.78%
external-auth 97.26%
pdf-viewer 96.26%
decisions-and-reasons 98.50%

… 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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues block approval of the React 18.3 compatibility changes.

No open issues 🎉

1 resolved since last review
1 file not reviewed
  • test/react18/package-lock.json: Generated file

Review effort: Balanced

This branch has not been deployed

No deployments
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.

2 participants