Skip to content

fix: keep backend errors from validators that did not run on the last save - #4381

Open
Bjarnisan wants to merge 1 commit into
Altinn:mainfrom
Bjarnisan:fix/keep-backend-validator-groups
Open

Bjarnisan wants to merge 1 commit into
Altinn:mainfrom
Bjarnisan:fix/keep-backend-validator-groups

Conversation

@Bjarnisan

@Bjarnisan Bjarnisan commented Oct 17, 2026 •

Copy link
Copy Markdown

Description

A save only returns issues from the validators that ran. Since #3753, useUpdateIncrementalValidations rebuilds the backend validations from the cached initial validations and the last save only. An error from an earlier save therefore disappears from the form when another validator runs on a later save, while the backend still has it and blocks submit. The issue has the steps and screenshots.

This PR keeps the backend validations grouped by validator in the validation store, as the ref in BackendValidation.tsx did before #3753:

  • backendValidatorGroups in the store holds the groups. updateBackendValidations now takes validator groups instead of data model validations, stores them, and maps them to data model validations itself.
  • The initial validation in BackendValidation.tsx sets the groups. A new fetch of the initial validations (process/next, UpdateShowAllErrors) still replaces them all.
  • useUpdateIncrementalValidations starts from the stored groups instead of the cached initial validations, and replaces only the groups in the last save. It is used after form data saves and after attachment tags are saved, so both keep the groups now.

processedLast, the task validations and waitForValidation are unchanged.

Same steps as in the issue, with app-frontend 4 from the CDN and with this branch:

CDN (4) This branch
cdn-2-etter-epost fix-2-etter-epost

v9 has the same code in src/App/frontend in altinn-studio, and also builds the component validations from the cached initial validations. I will make a separate PR there.

Related Issue(s)

Verification/QA

  • Manual functionality testing
    • I have tested these changes manually
    • Creator of the original issue (or service owner) has been contacted for manual testing (or will be contacted when released in alpha)
    • No testing done/necessary
  • Automated tests
    • Unit test(s) have been added/updated
    • Cypress E2E test(s) have been added/updated
    • No automatic tests are needed here (no functional changes/additions)
    • I want someone to help me make some tests
  • UU/WCAG (follow these guidelines until we have our own)
    • I have tested with a screen reader/keyboard navigation/automated wcag validator
    • No testing done/necessary (no DOM/visual changes)
    • I want someone to help me perform accessibility testing
  • User documentation @ altinn-studio-docs
    • Has been added/updated
    • No functionality has been changed/added, so no documentation is needed
    • I will do that later/have created an issue
  • Support in Altinn Studio
    • Issue(s) created for support in Studio
    • This change/feature does not require any changes to Altinn Studio
  • Sprint board
    • The original issue (or this PR itself) has been added to the Team Apps project and to the current sprint board
    • I don't have permissions to do that, please help me out
  • Labels
    • I have added a kind/* and backport* label to this PR for proper release notes grouping
    • I don't have permissions to add labels, please help me out

BackendValidation.test.tsx renders a form with two inputs and answers each save with the validators that ran:

  • An error from the phone validator stays when a later save only runs the email validator. This test fails on main.
  • An error is removed when its validator runs again and returns no issues. This passes on main too, and checks that the change does not keep errors a validator has cleared.

yarn tsc, yarn lint and the full yarn test pass locally on Node 22 (168 test suites and 3646 tests passed, 1 suite and 61 tests skipped). Every changed line and branch in the three source files is covered.

Manual test in localtest with a copy of one of our apps (Altinn.App 8.12.11) with two validators as in the issue. The local builds were loaded through localtest's frontendVersion cookie:

  • app-frontend 4 from the CDN and main (3ef668f) built locally: the phone number error disappears when the email is saved.
  • This branch built locally: the error stays. /validate returns the same issue in all three.

Summary by CodeRabbit

  • Bug Fixes
    • Backend validation errors now remain visible when a validator is omitted from a later save response.
    • Errors are cleared and fields return to a valid state when a validator reports no issues.
  • Tests
    • Added coverage for retaining omitted validator errors and clearing resolved errors.

… on the last save

A save only returns issues from the validators that ran. A custom validator whose
HasRelevantChanges returns false is left out of the response. Since the incremental
validations were moved into useUpdateIncrementalValidations (PR 3753), the backend
validations have been rebuilt from the initial validation and the last save only. An
error from an earlier save therefore disappeared as soon as another validator ran,
while it still blocked submit.

Keep the backend validations grouped by validator in the validation store, and let a
save replace only the groups of the validators that ran, as the frontend did before.
@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 90403a51-2612-4000-b8b9-fea72637f977
📥 Commits

Reviewing files that changed from the base of the PR and between 3ef668f and b95cbe8.

📒 Files selected for processing: 4
  • src/features/validation/backendValidation/BackendValidation.test.tsx
  • src/features/validation/backendValidation/BackendValidation.tsx
  • src/features/validation/backendValidation/useUpdateIncrementalValidations.ts
  • src/features/validation/validationContext.tsx

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

Backend validation state now retains validator groups across incremental saves. Validators omitted from a save response keep their existing validations, while validators that return an empty issue list clear their errors.

Changes: Backend validation updates

Layer / File(s) Summary
Store validator groups and map validations
src/features/validation/validationContext.tsx
Validation context stores backend validator groups, maps them to per-data-element validations, and provides a callback to read the stored groups.
Apply initial and incremental validation groups
src/features/validation/backendValidation/BackendValidation.tsx, src/features/validation/backendValidation/useUpdateIncrementalValidations.ts, src/features/validation/backendValidation/BackendValidation.test.tsx
Initial and incremental updates pass validator groups to the context. Incremental updates start from stored groups. Tests check that an omitted validator’s error remains and that an empty issue list clears the error.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: olemartinorg

Merge Risk: ⚪ Minimal · up to b95cb

This change keeps backend validation errors visible when a later save runs a different validator, and it clears them when the same validator runs again without issues. No actionable merge-blocking risk is identified from the supplied context.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description check Passed The description explains the bug, implementation, scope, related issue, manual testing, automated testing, accessibility decision, documentation decision, and release-process items. It also records te…
Title check Passed The title clearly and concisely describes the main change: retaining backend errors from validators that did not run on the latest save.
Linked Issues check Passed The changes satisfy issue #4380. backendValidatorGroups preserves each validator's field validations in the validation store. useUpdateIncrementalValidations starts from those groups and replaces …
Out of Scope Changes check Passed The changed source files implement the validator-group state flow for the linked issue. The added tests verify the required save behavior. No unrelated implementation or test changes are shown in the …
Full details: Description check

Explanation

The description explains the bug, implementation, scope, related issue, manual testing, automated testing, accessibility decision, documentation decision, and release-process items. It also records test results and known follow-up work for v9.

Full details: Linked Issues check

Explanation

The changes satisfy issue #4380. backendValidatorGroups preserves each validator's field validations in the validation store. useUpdateIncrementalValidations starts from those groups and replaces only validators returned by the latest save. An empty group clears that validator. Initial validation updates still replace all groups. BackendValidation.test.tsx covers both retention and clearing behavior.

Full details: Out of Scope Changes check

Explanation

The changed source files implement the validator-group state flow for the linked issue. The added tests verify the required save behavior. No unrelated implementation or test changes are shown in the pull request diff.

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Bjarnisan
Bjarnisan marked this pull request as ready for review October 17, 2026 21:08
@olemartinorg olemartinorg added kind/bug Something isn't working backport This PR should be cherry-picked onto older release branches labels Oct 20, 2026

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

backport This PR should be cherry-picked onto older release branches kind/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Backend validation error disappears when the user saves another field

2 participants