Skip to content

fix: Avoid error when switching frontend version if it also exists in comment in html-file#4290

Merged
phlipsterit merged 3 commits into
mainfrom
fix/4289-make-switch-frontend-version-more-robust
Jun 18, 2026
Merged

fix: Avoid error when switching frontend version if it also exists in comment in html-file#4290
phlipsterit merged 3 commits into
mainfrom
fix/4289-make-switch-frontend-version-more-robust

Conversation

@phlipsterit

@phlipsterit phlipsterit commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

If the html file loaded into the browser also contains a reference to the frontend in a comment, switching version from our internal dev tools would not work.

This is simply fixed by using replace all (/regexp/g) instead of just replace (/regexp/)

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

Summary by CodeRabbit

  • Refactor

    • Simplified and improved the devtools version switcher with a cleaner, more maintainable approach for reliably updating frontend assets when switching between versions.
  • Tests

    • Added comprehensive test coverage for version switching functionality to ensure stylesheet and script asset URLs update correctly across different selected versions.

@phlipsterit phlipsterit added kind/bug Something isn't working backport This PR should be cherry-picked onto older release branches labels Jun 17, 2026
@phlipsterit phlipsterit moved this to 🔎 In review in Team Altinn Studio Jun 17, 2026
@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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: ef62e45a-0c08-4754-9e83-eba337018bc5

📥 Commits

Reviewing files that changed from the base of the PR and between 08f67e8 and 1ec0e05.

📒 Files selected for processing (1)
  • src/features/devtools/components/VersionSwitcher/versionSwitcherUtils.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/features/devtools/components/VersionSwitcher/versionSwitcherUtils.ts

📝 Walkthrough

Walkthrough

Inline regex-based HTML asset URL mutations in VersionSwitcher's click handler are extracted into a new exported utility function replaceFrontendVersion in versionSwitcherUtils.ts. The click handler is updated to use this utility and gains an early-return guard when selectedVersion is absent. A Jest test suite is added for the new utility.

Changes

VersionSwitcher utility extraction and integration

Layer / File(s) Summary
replaceFrontendVersion utility and tests
src/features/devtools/components/VersionSwitcher/versionSwitcherUtils.ts, src/features/devtools/components/VersionSwitcher/versionSwitcherUtils.test.ts
New file exports replaceFrontendVersion(html, selectedVersion) which rewrites altinn-app-frontend.js and altinn-app-frontend.css CDN paths via global regex. Jest test verifies both URL replacements for version 4.60 while preserving surrounding HTML.
VersionSwitcher click handler refactor
src/features/devtools/components/VersionSwitcher/VersionSwitcher.tsx
Imports replaceFrontendVersion; click handler adds an early return when selectedVersion is absent and delegates HTML rewriting to the utility instead of inline regexes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the bug fix: avoiding an error when switching frontend versions when a version reference also exists in HTML comments.
Description check ✅ Passed The PR description explains the fix, references the related issue (#4289), and includes most verification/QA checkboxes, though manual testing and labels are not explicitly marked as completed.
Linked Issues check ✅ Passed The PR successfully addresses issue #4289 by implementing regex global replace to update all frontend version references in HTML, fixing the bug where version switching failed when commented versions existed.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the version-switching bug: the utility function, component integration, and test coverage are all in-scope for the stated objective.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/4289-make-switch-frontend-version-more-robust

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.

@phlipsterit phlipsterit added the squad/utforming Issues that belongs to the named squad. label Jun 17, 2026
Comment thread src/features/devtools/components/VersionSwitcher/VersionSwitcher.tsx Dismissed

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/features/devtools/components/VersionSwitcher/versionSwitcherUtils.ts`:
- Around line 4-7: The regex patterns in the replaceFrontendVersion function use
greedy matching with `.*` which can match too much content on minified lines or
when multiple tags exist on one line. Replace the `.*` patterns with non-greedy
alternatives that specifically match only the path characters (such as `[^/]*`
for the version path portion) to ensure each replacement targets only the
intended version string rather than matching from the first occurrence to the
last occurrence on a line.
🪄 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: 56866470-0476-491c-a576-454246137048

📥 Commits

Reviewing files that changed from the base of the PR and between c794096 and 08f67e8.

📒 Files selected for processing (3)
  • src/features/devtools/components/VersionSwitcher/VersionSwitcher.tsx
  • src/features/devtools/components/VersionSwitcher/versionSwitcherUtils.test.ts
  • src/features/devtools/components/VersionSwitcher/versionSwitcherUtils.ts

Comment thread src/features/devtools/components/VersionSwitcher/versionSwitcherUtils.ts Outdated
@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

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

See analysis details on SonarQube Cloud

@phlipsterit phlipsterit merged commit 34c39e6 into main Jun 18, 2026
13 of 16 checks passed
@phlipsterit phlipsterit deleted the fix/4289-make-switch-frontend-version-more-robust branch June 18, 2026 13:28
@github-project-automation github-project-automation Bot moved this from 🔎 In review to ✅ Done in Team Altinn Studio Jun 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Automatic backport successful!

A backport PR has been automatically created for the release/v4.31 release branch.

The release branch release/v4.31 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 kind/bug Something isn't working squad/utforming Issues that belongs to the named squad.

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

Det fungerer ikke å bytte frontendversjon fra devtools hvis det ligger en utkommentert versjon i index.html

3 participants