Skip to content

Conversation

@olemartinorg
Copy link
Contributor

@olemartinorg olemartinorg commented Dec 19, 2025

Description

🚧

Related Issue(s)

  • closes #17291

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

Summary by CodeRabbit

  • Bug Fixes
    • Improved "open by default" behavior for repeating groups to prevent interference when navigating to child components via links.
    • Enhanced focus handling in repeating groups to ensure proper navigation flow and component visibility.

✏️ Tip: You can customize this high-level summary in your review settings.

@olemartinorg olemartinorg added kind/bug Something isn't working backport This PR should be cherry-picked onto older release branches labels Dec 19, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 19, 2025

📝 Walkthrough

Walkthrough

The changes add a useBothRepGroups field to snapshot data, enhance the OpenByDefaultProvider to prevent interference with child component focus navigation, and introduce an end-to-end test for this behavior.

Changes

Cohort / File(s) Summary
Snapshot Data
snapshots.js
Added useBothRepGroups: false field to the nested-group object within the All process steps snapshot in two locations
RepeatingGroup Provider Logic
src/layout/RepeatingGroup/Providers/OpenByDefaultProvider.tsx
Added imports for useSearchParams, SearchParams, useLayoutLookups, splitDashedKey. Introduced useIsFocussingAChild hook to detect child component focus via URL parameters and layout lookups. Added memoized isFocusingChildRef runtime check to exclude open-by-default editing when a child component is about to receive focus. Extended effect dependency array to include the new ref.
End-to-End Test
test/e2e/integration/frontend-test/group.ts
Added new end-to-end test "openByDefault should not prevent navigation via linkToComponent" that verifies navigation between group components with openByDefault configuration, including focus handling, validation, and viewport positioning

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

  • OpenByDefaultProvider.tsx: The new useIsFocussingAChild hook and its integration with the effect logic requires careful review to ensure correct prevention of interference with child component focus, including proper dependency tracking with isFocusingChildRef.
  • group.ts: The test appears duplicated in the diff (two insertions of the same sequence); verify this is intentional and review all navigation scenarios and assertions are correctly implemented.
  • snapshots.js: Cross-reference the two snapshot locations to ensure both updates are consistent and complete.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Description check ❓ Inconclusive The description is incomplete with only a construction emoji and no substantive detail about the changes, though the related issue is referenced and verification checklist is present. Replace the construction emoji with a clear summary of the changes made, explaining how the fix addresses the linkToComponent and openByDefault interaction issue.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main bug being fixed: the broken linkToComponent functionality when openByDefault is set to 'first'.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bug/link-openbydefault

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
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: 0

🧹 Nitpick comments (1)
src/layout/RepeatingGroup/Providers/OpenByDefaultProvider.tsx (1)

95-116: Well-implemented helper hook.

The logic correctly identifies whether the focus target is a descendant of the repeating group by traversing up the component parent chain. The hook properly calls React hooks unconditionally before any conditional returns.

Minor naming note: The function uses "Focussing" (British spelling) while other parts of the codebase might use "Focusing" (American spelling). Consider standardizing if there's a preference in the project.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 57d7ac0 and bff1857.

📒 Files selected for processing (3)
  • snapshots.js (1 hunks)
  • src/layout/RepeatingGroup/Providers/OpenByDefaultProvider.tsx (4 hunks)
  • test/e2e/integration/frontend-test/group.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: Avoid using any type or type casting (as type) in TypeScript code; improve typing by avoiding casts and anys when refactoring
Use objects for managing query keys and functions, and queryOptions for sharing TanStack Query patterns across the system for central management

Files:

  • src/layout/RepeatingGroup/Providers/OpenByDefaultProvider.tsx
  • test/e2e/integration/frontend-test/group.ts
{**/*.module.css,**/*.{ts,tsx}}

📄 CodeRabbit inference engine (CLAUDE.md)

Use CSS Modules for component styling and leverage Digdir Design System components when possible

Files:

  • src/layout/RepeatingGroup/Providers/OpenByDefaultProvider.tsx
  • test/e2e/integration/frontend-test/group.ts
🧠 Learnings (3)
📚 Learning: 2025-08-28T12:00:32.967Z
Learnt from: olemartinorg
Repo: Altinn/app-frontend-react PR: 3645
File: src/features/datamodel/DataModelsProvider.tsx:172-175
Timestamp: 2025-08-28T12:00:32.967Z
Learning: In DataModelsProvider.tsx, the effect that processes referenced data types must run for both stateless and non-stateless apps. The `isFetching` guard is appropriate because stateless apps don't fetch instance data (useInstanceDataQuery is disabled with `enabled: !isStateless`) but still need the data type processing to occur.

Applied to files:

  • src/layout/RepeatingGroup/Providers/OpenByDefaultProvider.tsx
📚 Learning: 2025-11-25T12:53:54.399Z
Learnt from: CR
Repo: Altinn/app-frontend-react PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T12:53:54.399Z
Learning: Applies to **/*.test.{ts,tsx} : Use `renderWithProviders` from `src/test/renderWithProviders.tsx` when testing components that require form layout context

Applied to files:

  • src/layout/RepeatingGroup/Providers/OpenByDefaultProvider.tsx
📚 Learning: 2025-11-25T12:53:54.399Z
Learnt from: CR
Repo: Altinn/app-frontend-react PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T12:53:54.399Z
Learning: Reduce dependency on React Context and migrate state management towards React Query patterns instead of Zustand wrappers

Applied to files:

  • src/layout/RepeatingGroup/Providers/OpenByDefaultProvider.tsx
🧬 Code graph analysis (1)
src/layout/RepeatingGroup/Providers/OpenByDefaultProvider.tsx (3)
src/hooks/useAsRef.ts (1)
  • useAsRef (12-16)
src/features/form/layout/LayoutsContext.tsx (1)
  • useLayoutLookups (102-102)
src/utils/splitDashedKey.ts (1)
  • splitDashedKey (18-48)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Type-checks, eslint, unit tests and SonarCloud
  • GitHub Check: Install
🔇 Additional comments (4)
snapshots.js (1)

254-254: LGTM!

The new useBothRepGroups field aligns the snapshot data with the updated test scenario in group.ts, where this field is used to toggle the radio button that exercises the linkToComponent navigation behavior.

src/layout/RepeatingGroup/Providers/OpenByDefaultProvider.tsx (2)

46-47: LGTM!

Using useAsRef here ensures the ref identity remains stable (preventing unnecessary effect re-runs) while still providing access to the latest computed value via .current when the effect executes.


74-84: LGTM!

The added condition !isFocusingChildRef.current correctly prevents openByDefault from interfering when the user is navigating to a specific child component via linkToComponent. This is the core fix for the reported bug.

test/e2e/integration/frontend-test/group.ts (1)

424-487: Excellent regression test coverage.

This test comprehensively validates the fix by:

  1. Verifying openByDefault: 'first' works initially
  2. Testing that linkToComponent navigation to a child component bypasses the openByDefault behavior (Lines 462-469)
  3. Confirming that openByDefault still triggers when focus moves outside the group (Lines 475-483)
  4. Ensuring no layout shift affects the focused element (Line 486)

The test effectively captures the bug scenario and validates the expected behavior in both directions.

@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
16.67% Condition Coverage on New Code (required ≥ 45%)

See analysis details on SonarQube Cloud

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.

1 participant