Skip to content

Fix issue with broken RemoveHiddenData when a whole page is hidden#1721

Merged
ivarne merged 4 commits intomainfrom
fix/removeHiddenData
Apr 21, 2026
Merged

Fix issue with broken RemoveHiddenData when a whole page is hidden#1721
ivarne merged 4 commits intomainfrom
fix/removeHiddenData

Conversation

@ivarne
Copy link
Copy Markdown
Member

@ivarne ivarne commented Apr 15, 2026

The root cause was that there is no removeWhenHidden property on pages, so the PageComponent was initialized with null in that field.

ExpressionValue.ToBoolLoose() copies expression semantics that treat null as false, so in BaseComponent.ShouldRemoveWhenHidden we now check for null, because for that property null and undefined must be treated as true.

Summary by CodeRabbit

  • Bug Fixes

    • Hidden-component removal now treats null/undefined expression values consistently so hidden fields are removed or retained as configured.
  • New Features

    • Added an explicit "undefined" expression value to represent undefined expression state.
  • Tests

    • Expanded tests to cover additional hidden-page scenarios and verify removal behavior.
  • API

    • Public schema updated to include two new nullable string fields for hidden-page data.

The root cause was that there is no `removeWhenHidden` property on pages, so the `PageComponent` was initialized with `null` in that field.

ExpressionValue.ToBoolLoose() copies expression semantics that treat `null` as `false`, so in `BaseComponent.ShouldRemoveWhenHidden` we now check for null, because for that property null and undefined must be treated as true.
@ivarne ivarne added bugfix Label Pull requests with bugfix. Used when generation releasenotes backport This PR should be cherry-picked onto older release branches labels Apr 15, 2026
Copilot AI review requested due to automatic review settings April 15, 2026 10:47
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 15, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fbf25bd5-b0ab-41c2-94e7-b675bfb37c45

📥 Commits

Reviewing files that changed from the base of the PR and between 308a952 and 87f8246.

📒 Files selected for processing (2)
  • test/Altinn.App.Api.Tests/OpenApi/OpenApiSpecChangeDetection.SaveCustomOpenApiSpec.verified.json
  • test/Altinn.App.Core.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt
🚧 Files skipped from review as they are similar to previous changes (1)
  • test/Altinn.App.Core.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt

📝 Walkthrough

Walkthrough

Adds an Expression.Undefined sentinel, adjusts RemoveWhenHidden evaluation to treat JSON null/undefined as no-value, precomputes unclaimed child components for pages, and extends tests and test assets with a new hidden page and its fields.

Changes

Cohort / File(s) Summary
Expression core
src/Altinn.App.Core/Models/Expressions/Expression.cs
Added public static Expression Undefined => new(ExpressionValue.Undefined) singleton.
Layout evaluation
src/Altinn.App.Core/Models/Layout/Components/Base/BaseComponent.cs
ShouldRemoveWhenHidden(...) now treats evaluated RemoveWhenHidden values with JsonValueKind.Null or JsonValueKind.Undefined as no-value and returns the default true; other kinds still use ToBoolLoose() with a true fallback when conversion yields null.
Page component
src/Altinn.App.Core/Models/Layout/Components/PageComponent.cs
Precomputes childComponentList of components not in claimedComponentIds and returns that as ChildComponents; sets returned PageComponent.RemoveWhenHidden to Expression.Undefined (was Expression.Null).
Test models & layout assets
test/Altinn.App.Api.Tests/Data/apps/tdd/contributer-restriction/models/Skjema.cs, test/Altinn.App.Api.Tests/Data/apps/tdd/contributer-restriction/ui/default/Settings.json, test/Altinn.App.Api.Tests/Data/apps/tdd/contributer-restriction/ui/default/layouts/hidden_page.json
Added nullable properties HiddenPage and HiddenPageNotRemove with XML/JSON serialization attributes; inserted hidden_page into pages order; added hidden_page.json layout declaring a hidden page and two inputs with differing removeWhenHidden settings.
Controller & data tests
test/Altinn.App.Api.Tests/Controllers/ProcessControllerTests.cs, test/Altinn.App.Api.Tests/Controllers/DataController_LayoutEvaluatorTests.cs
Extended tests to include melding.hiddenPage and melding.hiddenPageNotRemove in process/data-write assertions and JSON patch operations; updated expected saved data and DataReference counts.
Public API & OpenAPI snapshots
test/Altinn.App.Core.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt, test/Altinn.App.Api.Tests/OpenApi/OpenApiSpecChangeDetection.SaveCustomOpenApiSpec.verified.json
Public API snapshot updated to include Expression.Undefined; OpenAPI verified spec updated to add hiddenPage and hiddenPageNotRemove nullable string properties to components.schemas.Dummy.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and specifically summarizes the main bug fix: resolving the broken RemoveHiddenData functionality when an entire page is hidden.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/removeHiddenData

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 and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/Altinn.App.Core/Models/Layout/Components/Base/BaseComponent.cs (1)

108-114: Handle JsonValueKind.Undefined explicitly in the default branch.

Given the new Expression.Undefined path, explicitly including Undefined here makes behavior unambiguous and independent of ToBoolLoose() semantics.

Proposed diff
-        if (removeWhenHidden.ValueKind == JsonValueKind.Null)
+        if (removeWhenHidden.ValueKind is JsonValueKind.Null or JsonValueKind.Undefined)
         {
             // ToBoolLoose returns false when the value is null, but we want to return the default value in that case, so we check for null before calling ToBoolLoose()
             return defaultShouldRemove;
         }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Altinn.App.Core/Models/Layout/Components/Base/BaseComponent.cs` around
lines 108 - 114, The current default branch in BaseComponent.cs treats only
JsonValueKind.Null separately but doesn't handle JsonValueKind.Undefined
introduced by Expression.Undefined, so update the check around removeWhenHidden
in the method (referencing removeWhenHidden, ToBoolLoose(), and the
BaseComponent class) to explicitly treat both JsonValueKind.Null and
JsonValueKind.Undefined as the default case (return defaultShouldRemove) before
calling ToBoolLoose(), ensuring behavior is deterministic and not relying on
ToBoolLoose() semantics.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@test/Altinn.App.Api.Tests/Controllers/ProcessControllerTests.cs`:
- Around line 475-476: Replace FluentAssertions usage in the test assertions
with xUnit asserts: change the two calls on dataString (the lines using
dataString.Should().Contain("<hiddenPage>...") and
dataString.Should().Contain("<hiddenPageNotRemove>...")) to use Assert.Contains
for strings that must be present and Assert.DoesNotContain for strings that must
not be present; also update the similar pair around lines 490-491 accordingly so
all four assertions follow the repo convention (use Assert.Contains /
Assert.DoesNotContain with the same expected substring and actual dataString).

---

Nitpick comments:
In `@src/Altinn.App.Core/Models/Layout/Components/Base/BaseComponent.cs`:
- Around line 108-114: The current default branch in BaseComponent.cs treats
only JsonValueKind.Null separately but doesn't handle JsonValueKind.Undefined
introduced by Expression.Undefined, so update the check around removeWhenHidden
in the method (referencing removeWhenHidden, ToBoolLoose(), and the
BaseComponent class) to explicitly treat both JsonValueKind.Null and
JsonValueKind.Undefined as the default case (return defaultShouldRemove) before
calling ToBoolLoose(), ensuring behavior is deterministic and not relying on
ToBoolLoose() semantics.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 148bd19f-ff23-4f60-9243-6bcde4c71d03

📥 Commits

Reviewing files that changed from the base of the PR and between 05b78a4 and 8f81363.

📒 Files selected for processing (8)
  • src/Altinn.App.Core/Models/Expressions/Expression.cs
  • src/Altinn.App.Core/Models/Layout/Components/Base/BaseComponent.cs
  • src/Altinn.App.Core/Models/Layout/Components/PageComponent.cs
  • test/Altinn.App.Api.Tests/Controllers/ProcessControllerTests.cs
  • test/Altinn.App.Api.Tests/Data/apps/tdd/contributer-restriction/models/Skjema.cs
  • test/Altinn.App.Api.Tests/Data/apps/tdd/contributer-restriction/ui/default/Settings.json
  • test/Altinn.App.Api.Tests/Data/apps/tdd/contributer-restriction/ui/default/layouts/hidden_page.json
  • test/Altinn.App.Core.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt

Comment thread test/Altinn.App.Api.Tests/Controllers/ProcessControllerTests.cs
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes hidden-data removal behavior when an entire page is hidden by ensuring removeWhenHidden defaults correctly for pages and by adding regression coverage.

Changes:

  • Adjust page component initialization to use an “undefined” removeWhenHidden value (instead of null) so default removal semantics apply.
  • Update BaseComponent.ShouldRemoveWhenHidden to treat null as “use default” (true) rather than as false.
  • Add an API test app layout + extended controller test assertions to cover hidden whole-page scenarios.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/Altinn.App.Core.Tests/PublicApiTests.PublicApi_ShouldNotChange_Unintentionally.verified.txt Updates public API snapshot to include Expression.Undefined.
test/Altinn.App.Api.Tests/Data/apps/tdd/contributer-restriction/ui/default/layouts/hidden_page.json Adds a hidden page layout to reproduce/cover whole-page hidden removal behavior.
test/Altinn.App.Api.Tests/Data/apps/tdd/contributer-restriction/ui/default/Settings.json Adds the new hidden page to the page order for the test app.
test/Altinn.App.Api.Tests/Data/apps/tdd/contributer-restriction/models/Skjema.cs Extends the test model with fields bound to the new hidden page components.
test/Altinn.App.Api.Tests/Controllers/ProcessControllerTests.cs Extends the existing hidden-data removal test to include hidden-page fields.
src/Altinn.App.Core/Models/Layout/Components/PageComponent.cs Sets page RemoveWhenHidden to Expression.Undefined and minor refactor for child list creation.
src/Altinn.App.Core/Models/Layout/Components/Base/BaseComponent.cs Updates ShouldRemoveWhenHidden to treat null as “default true”.
src/Altinn.App.Core/Models/Expressions/Expression.cs Adds Expression.Undefined convenience literal.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Altinn.App.Core/Models/Expressions/Expression.cs
@ivarne ivarne enabled auto-merge (squash) April 21, 2026 06:25
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
D Maintainability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@ivarne ivarne merged commit cc667d3 into main Apr 21, 2026
13 of 14 checks passed
@ivarne ivarne deleted the fix/removeHiddenData branch April 21, 2026 06:34
@github-actions
Copy link
Copy Markdown

Automatic backport successful!

A backport PR has been automatically created for the release/v8.11 release branch.

The release branch release/v8.11 already existed and was updated.

The cherry-pick was clean with no conflicts. Please review the backport PR when it appears.

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 bugfix Label Pull requests with bugfix. Used when generation releasenotes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants