Repository navigation
fix: avoid crash when links to components change in dynamic texts - #4386
Conversation
Links made with linkToComponent are parsed from text without stable keys, so React reused a LinkToPotentialNode for a link with another target when a link was removed from the middle of a list. useIsHidden throws when its component id changes. Key the inner component on the target so a new target mounts fresh.
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes. ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
|
Looks good! Fixes for the cypress failures got merged into main now |
|
✅ Automatic backport successful! A backport PR has been automatically created for the The release branch The cherry-pick was clean with no conflicts. Please review the backport PR when it appears. |
|
/publish |
) Links made with linkToComponent are parsed from text without stable keys, so React reused a LinkToPotentialNode for a link with another target when a link was removed from the middle of a list. useIsHidden throws when its component id changes. Key the inner component on the target so a new target mounts fresh.
PR release:
|
Description
A component crashed with
useIsHidden doesn't support changing the baseComponentId, that would break the rule of hookswhen its text had a list oflinkToComponentlinks and a link was removed from the middle of the list. A service owner hit this with an Alert listing the rows in a table that need fixing: when one row was fixed, the Alert crashed until the page was refreshed.Summary
Links in texts are parsed from HTML and keyed by their position. When a link in the middle is removed, React reuses the
LinkToPotentialNodeat that position for the next link, which has another target.useIsHiddenthrows when its component id changes.LinkToPotentialNodenow reads the target and renders the existing logic in an inner component keyed on the target, so a new target mounts a new component:Evidence
Manual test in localtest with a copy of
ttd/component-libraryand a page with three inputs and an Alert listing alinkToComponentlink for each input with the valuex. This branch was loaded through localtest'sfrontendVersioncookie. Fill all three, then clear the middle one:All rows filled:
Before (
main), middle row cleared: the Alert crashes.After (this branch), middle row cleared: the Alert lists Rad 1 and Rad 3.
After the fix, the remaining "Rad 3" link still moves focus to the right input.
LinkToPotentialNode.test.tsx:useIsHiddenerror.Merge Danger
Door: two-way
Blast Radius: small
Only
LinkToPotentialNodechanges. Its output is the same; it now remounts when its target changes instead of reusing the old component.useIsHiddenstill gets the fullfocusComponentId, so for targets inside a repeating group (e.g.comp-0) the hidden expressions are not found. That is a separate, existing bug and is not changed here. v9 insrc/App/frontendin altinn-studio has the sameLinkToPotentialNodeand needs the same fix.Related Issue(s)
Verification/QA
kind/*andbackport*label to this PR for proper release notes groupingSummary by CodeRabbit
Bug Fixes
Tests