Skip to content

chore(lint): enforce useHeadlessForm over direct createHeadlessForm imports - #1439

Merged
gabrielseco merged 32 commits into
mainfrom
chore/enforce-use-headless-form
Oct 5, 2026
Merged

gabrielseco merged 32 commits into
mainfrom
chore/enforce-use-headless-form

Conversation

@gabrielseco

@gabrielseco gabrielseco commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

New JSON Schema forms now have to be built through our shared form hook. Lint fails on any new code that calls the form engine directly.

Why

#1433 adds useHeadlessForm so we stop rebuilding forms on every keystroke. Docs and Bugbot can only ask for the new pattern. A lint error blocks the merge, so new direct calls can't creep back in while the rollout is still going.

The agent docs (CLAUDE.md, the Cursor rule) still taught the old "call createHeadlessForm once" pattern, so agents would have kept writing it.

What changed

Toggle details
  • .oxlintrc.json: no-restricted-imports bans the createHeadlessForm import from @remoteoss/remote-json-schema-form-kit and from any **/common/createHeadlessForm path (alias or relative). Other kit imports like ValidationResult are still allowed.
  • The rule always fails. The 13 legacy call sites carry // oxlint-disable-next-line no-restricted-imports -- TODO: move onto useHeadlessForm on the import, so the debt sits next to the code and grep -rn "no-restricted-imports -- TODO" src lists it. overrides only keep permanent exceptions: the wrapper, the hook, tests and scripts/.
  • npm run lint now passes --report-unused-disable-directives-severity=error, so migrating a file fails lint until its comment is removed. Turning this on surfaced three existing directives that no longer suppressed anything (form.tsx, file-uploader.tsx, createHeadlessForm.tsx), which are removed. Their explanatory comments stay.
  • CLAUDE.md, .cursor/rules/json-schema-form-usage.mdc, .cursor/BUGBOT.md: rewritten around fetch schema → useHeadlessForm({ schema, initialValues, options, strategy: 'buildOnce' }), with initialValues being the saved values (not the live form values). Bugbot also flags new disable comments for the rule and new rebuild usage.
  • docs/USE_HEADLESS_FORM_ROLLOUT.md: the lint rule moves from phase 3 to now. Removing the last TODO disable comment is the remaining phase 3 item.

Stacked on #1433, which this PR targets. No public API change.

Screenshots

N/A

Related Resources

Testing

  • Added a probe file importing createHeadlessForm through the alias, a relative path and the kit. All three error with the message pointing at useHeadlessForm. The probe was not committed.

  • npm run lint exits 0 on the branch. A probe with a stale disable comment fails with "Unused oxlint-disable directive".

  • Tested against the example/ app in a browser

  • Feature flag: N/A

🤖 Generated with Claude Code


Note

Medium Risk
Changes onboarding JSON Schema validation, money display, and submit parsing for benefits and engagement agreement details—areas sensitive to cents conversion and conditional fields.

Overview
This PR locks in the useHeadlessForm pattern with oxlint no-restricted-imports on createHeadlessForm (legacy call sites keep a tracked TODO disable), turns on unused disable directive errors in lint, and rewrites agent docs (CLAUDE.md, Cursor rule, BUGBOT.md, rollout doc) around fetch schema → hook with buildOnce and saved initialValues.

Onboarding moves benefits and engagement agreement details off React Query select + createHeadlessForm onto useHeadlessForm; hooks.tsx seeds saved values (not live field values), routes validate/parse/submit and value changes through the hook helpers, and drops hand-rolled parseJSFToValidate for those steps. Germany dynamic-steps tests cover salary-range validation and POST payloads still in cents.

Remaining direct createHeadlessForm imports are annotated for rollout; a few stale oxlint-disable lines are removed.

Reviewed by Cursor Bugbot for commit f27a6b0. Bugbot is set up for automated code reviews on this repo. Configure here.

cammellos and others added 18 commits September 29, 2026 18:32
Portugal's extended work hours allowance is a forced money value computed
from the salary. Onboarding built its render-time form without converting
money fields to cents, so the allowance was computed from the salary in
major units (100x too small), and the forced value was then written into
the form state in cents while the form keeps money in major units.
Validation recomputed the correct value and rejected the submission on a
field with no input to show the error, blocking the step.

- Onboarding's useJSONSchemaForm passes transformMoneyFields: true, since
  createHeadlessForm only defaults it on when no options are passed.
- Forced money values are converted from cents before being set in the form.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Default transformMoneyFields to true whenever it's not explicitly set,
instead of only when the whole options object is missing. Callers that
pass options without transformMoneyFields (e.g. only jsfModify) now get
money fields converted to cents too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tails path

The flow regression test only covers the legacy path while PRT is outside
JSF_V1_CONTRACT_DETAILS_COUNTRIES. These test the Onboarding useJSONSchemaForm
hook and JSONSchemaFormFields directly, so they keep covering the fix
whichever countries are on v1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Submitting a forced value already uses the field's `const` in cents
(parseFormValuesToAPI overwrites the form value with it), and the default
forced value component doesn't render `value`. The `transformMoneyFields`
change alone fixes the PRT allowance; getForcedValue would only change
what custom forcedValue components receive in `fieldData.value`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Correct submission of forced money values relies on parseFormValuesToAPI
overwriting the form value with the field's const. Covers a top-level field
and one nested in a fieldset; both fail with 100x the amount without it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
createHeadlessForm now defaults transformMoneyFields per key (#1426), so
the explicit override in useJSONSchemaForm is redundant.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…gies

Every flow wires createHeadlessForm, parseJSFToValidate and handleValidation
by hand, and each copy can drift on its own (the money unit regression lived
in one of them). useHeadlessForm puts that wiring behind one interface with
the two strategies the codebase uses today:

- rebuild: rebuild the form whenever values change (current behaviour of
  most call sites).
- buildOnce: build once per schema/options and resolve conditionals through
  handleValidation. It validates once after every build, so visibility is
  right without a mounted step and an inline jsfModify reference does not
  reset it; a replaced form's pending validation is cancelled before it
  mutates the old fields.

The engine contract test renders the real useJSONSchemaForm +
JSONSchemaFormFields (so ForcedValueField's setValue loop runs) and runs
each schema situation across jsf v0, jsf v1, no meta and both strategies.
New situations are one row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ssForm

First call site on the shared hook, with the rebuild strategy so behaviour
is unchanged. useLegacyContractDetailsSchema fetches the raw schema and
leaves building to the hook; the shared useJSONSchema stays as it is for the
other steps. mergedFormValues moves out of that wrapper so both can use it.

The existing PRT extended hours allowance flow test covers this step: it
fails when the hook's rebuild stops converting money to cents.

The jsonSchemaVersion test's mocked schema gains x-jsf-presentation, like
every real schema has: the hook builds during render instead of inside a
React Query select, so the money conversion's lookup of it now surfaces
instead of turning into a silent query error.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… options

buildOnce rebuilt the form whenever the options object changed identity, and
every build validates and re-renders. A caller that creates options during
render (as the Onboarding contract details hooks do) looped forever: 132
renders in 500ms in a probe, "Too many re-renders" in the test.

Options are now compared by value with fast-deep-equal, the helper
useJSONSchemaForm already uses. Functions and components inside jsfModify
keep their identity across our own renders, so they compare equal by
reference. React elements cannot reach jsfModify: the jsf engine
deep-clones it and rejects them, so the React-aware variant is not needed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ssForm

The v1 contract details (FRA, ITA, DEU, ESP) already built the form once and
resolved conditionals through handleValidation with invisible values kept,
which is the hook's buildOnce strategy. useContractDetailsSchema now hands
building, validation and submit parsing to the hook, so contract details
covers both strategies: the legacy step with rebuild, v1 with buildOnce.

The fieldsCount state that forced a re-render after each v1 validation goes
away, since the hook re-renders itself. The comment on why invisible values
are kept moves with that decision into the hook. The replay after a rebuild
uses the step's form values, not the server employment data, so money is
never converted from cents a second time on this path.

France's flow tests and useOnboardingJsfV1ContractDetails fail when the
hook's buildOnce validation is broken, so they cover this step.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both contract details schema requests send employment_id, but their query
keys only held the country and schema version, so React Query served the
first employment's schema to every other employment of the same country in
the session, and never refetched once an employment was created mid-flow.
The keys now include the request query.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The contract only built forms without options, which is the one shape where
createHeadlessForm's money default is irrelevant, so reverting that default to
the old `options || { transformMoneyFields: true }` stayed green here and was
only caught by flow and hook tests. Run every situation with no options, with
an options object carrying no jsfModify (what Onboarding passes when the
consumer gives none), and with a real jsfModify whose effect is asserted.

Mutation checked: the old default fails the 6 rebuild money rows, and dropping
options inside useHeadlessForm fails the 6 jsfModify rows.

The Onboarding useJSONSchemaForm money forced value test is removed: its
engine check is now in the contract and its wiring is covered end to end by
the OnboardingFlow allowance-in-cents test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…mports

Adds a no-restricted-imports rule that bans importing createHeadlessForm
from the kit or the common wrapper. Legacy call sites are allowlisted in
an override; each migration PR removes its file from the list.

Rewrites the CLAUDE.md forms guidance, the json-schema-form-usage Cursor
rule and the BUGBOT.md forms section around the useHeadlessForm pattern,
and moves the lint rule out of the rollout doc's phase 3.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Deploy preview for remote-flows ready!

Project:remote-flows
Status: ✅  Deploy successful!
Preview URL:https://remote-flows-qnjffp9sv-remotecom.vercel.app
Latest Commit:f27a6b0

Deployed with vercel-action

@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Deploy preview for adp-cost-calculator ready!

Project:adp-cost-calculator
Status: ✅  Deploy successful!
Preview URL:https://adp-cost-calculator-qpaj1g28r-remotecom.vercel.app
Latest Commit:f27a6b0

Deployed with vercel-action

@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

📊 Coverage Report

✅ Coverage increased! 🎉

Metric Current Previous Change Status
Lines 86.72% 86.71% +0.01% 🟢
Statements 86.28% 86.27% +0.01% 🟢
Functions 85.26% 85.25% 0% ⚪
Branches 78.05% 78.06% 0% ⚪

Detailed Breakdown

Lines Coverage
  • Covered: 4969 / 5730
  • Coverage: 86.72%
  • Change: +0.01% (5 lines)
Statements Coverage
  • Covered: 5056 / 5860
  • Coverage: 86.28%
  • Change: +0.01% (5 statements)
Functions Coverage
  • Covered: 1319 / 1547
  • Coverage: 85.26%
  • Change: 0% (1 functions)
Branches Coverage
  • Covered: 3073 / 3937
  • Coverage: 78.05%
  • Change: 0% (3 branches)

✅ Coverage check passed

… an allowlist

The rule now always fails. Each legacy import carries an
oxlint-disable-next-line comment with a TODO, so the remaining debt sits
next to the code and is greppable. The overrides only keep permanent
exceptions: the wrapper, the hook, tests and scripts.

Lint now reports unused disable directives as errors, so migrating a file
forces removing its comment. That surfaced three directives that no
longer suppressed anything, which are removed.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

📦 Bundle Size Report

Metric Current Previous Change Status
Total (gzip) 225.63 kB 225.57 kB +61 B (+0.0%) 🔴
Total (raw) 629.55 kB 629.22 kB +330 B (+0.1%) 🔴
CSS (gzip) 21.94 kB 21.94 kB 0 B (0%) 🟢
CSS (raw) 114.43 kB 114.43 kB 0 B (0%) 🟢

Size Limits

  • ✅ Total gzipped: 225.63 kB / 350 kB (64.5%)
  • ✅ Total raw: 629.55 kB / 850 kB (74.1%)
  • ✅ CSS gzipped: 21.94 kB / 25 kB (87.8%)

Largest Files (Top 5)

  1. index.esm-wIkXrqU6.js - 11.4 kB (0 B (0%))
  2. styles.css - 10.97 kB (0 B (0%))
  3. index.css - 10.97 kB (0 B (0%))
  4. internals-fOP6WDD_.js - 6.14 kB (new)
  5. hooks-BVUkbLi2.js - 5.8 kB (new)
View All Files (289 total)
File Size (gzip) Change
index.esm-wIkXrqU6.js 11.4 kB 0 B (0%)
styles.css 10.97 kB 0 B (0%)
index.css 10.97 kB 0 B (0%)
internals-fOP6WDD_.js 6.14 kB new
hooks-BVUkbLi2.js 5.8 kB new
index.js 5.52 kB 0 B (0%)
sdk.gen-hikpofx9.js 5.48 kB 0 B (0%)
flows/Onboarding/hooks.js 4.36 kB +24 B (+0.6%)
utils-qfe-oQBs.js 4.07 kB 0 B (0%)
FieldSetField-Bds5UIuj.js 4.03 kB 0 B (0%)

✅ Bundle size check passed

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Comment thread src/common/createHeadlessForm.tsx
Comment thread src/components/ui/file-uploader.tsx
Comment thread src/components/ui/form.tsx
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Comment thread package.json
gabrielseco and others added 5 commits October 5, 2026 11:02
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…c information onto useHeadlessForm

useHeadlessForm's buildOnce strategy now takes initialValues and resolves
conditional visibility at build time instead of replaying values in a
post-mount effect. Rebuilds triggered by jsfModify reuse the last validated
values for the same schema, while a new schema starts from initialValues.

Onboarding's basic_information step now goes through useBasicInformationSchema
(buildOnce) and contract details receives saved employment values as
initialValues rather than the live fieldValues.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…contract test

The buildOnce rebuild/seed rules (initialValues on first render and when they
arrive late, last validated values surviving a jsfModify change and beating
initialValues, a new schema starting from initialValues) now run through the
real form on jsf v0, jsf v1 and no meta, instead of a renderHook test on the
jsf v1 fixture only.

The render-count guard is dropped: the hook no longer validates after each
build, so recreated options cannot cause a render loop anymore.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…llout

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
gabrielseco and others added 2 commits October 5, 2026 12:49
… chore/enforce-use-headless-form

# Conflicts:
#	docs/USE_HEADLESS_FORM_ROLLOUT.md
…orm guidance

buildOnce now takes initialValues instead of values (#1433), so the CLAUDE.md,
Cursor rule and Bugbot examples would have produced a type error.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…eHeadlessForm ban

Tests also live in __tests__ folders and next to source as *.test.ts(x),
not only under tests/, so the override now covers them too, matching the
guidance that tests may use the engine directly.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Base automatically changed from refactor/use-headless-form to main October 5, 2026 16:30
gabrielseco and others added 2 commits October 5, 2026 18:30
… once through useHeadlessForm (#1442)

* refactor(onboarding): build benefits and engagement agreement details once through useHeadlessForm

Both schema hooks now fetch the raw schema and hand it to useHeadlessForm with
the buildOnce strategy, seeded with the saved values (partner initialValues
plus the saved benefit offers / engagement agreement details). Validation,
submit parsing and value changes for both steps go through the hook instead
of the hand-written parseJSFToValidate branches in hooks.tsx, and the forms
are no longer rebuilt on every keystroke from the live field values.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* docs(form): mark benefits and engagement agreement details as migrated to buildOnce

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

* add tests to verify values

---------

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@gabrielseco
gabrielseco merged commit 4793eca into main Oct 5, 2026
14 checks passed
@gabrielseco
gabrielseco deleted the chore/enforce-use-headless-form branch October 5, 2026 16:41
@gabrielseco gabrielseco mentioned this pull request Oct 6, 2026
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