Skip to content

fix(link-checker): reload page when installation params change on visibility restored [ES-322]#11030

Open
david-shibley-contentful wants to merge 4 commits into
masterfrom
fix/link-checker-stale-params-es-322
Open

fix(link-checker): reload page when installation params change on visibility restored [ES-322]#11030
david-shibley-contentful wants to merge 4 commits into
masterfrom
fix/link-checker-stale-params-es-322

Conversation

@david-shibley-contentful

@david-shibley-contentful david-shibley-contentful commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

ES-322

Summary

  • sdk.parameters.installation is a static snapshot from when the app iframe loaded. If a user updates the allow list in config and returns to the page app without a hard refresh, scans run against stale params — causing valid links to show as "Not on allow list"
  • Add a visibilitychange listener that fetches current installation parameters from the CMA when the tab becomes visible again and calls window.location.reload() if they differ — the in-app equivalent of the hard-refresh workaround given to the customer
  • Errors from the CMA fetch are silently swallowed so a failed check never blocks the user

Test plan

  • Update the allow list in Link Checker config, then navigate back to the page app — it should automatically reload and show the updated results without requiring a manual hard refresh
  • Verify that navigating away and back without changing config does NOT trigger a reload
  • Run npm test in apps/link-checker — all 60 tests pass including 2 new cases covering the reload and no-reload paths

Generated with Claude Code

@david-shibley-contentful david-shibley-contentful requested review from a team as code owners June 17, 2026 20:37
david-shibley-contentful and others added 3 commits June 17, 2026 16:33
…ibility restored [ES-322]

sdk.parameters.installation is a static snapshot from when the app
iframe loaded. If a user updates the allow list in config and returns to
the page app without a hard refresh, scans run against stale params —
causing links to show as invalid even though they're on the allow list.

Add a visibilitychange listener that fetches the current app installation
parameters from the CMA when the tab becomes visible again and calls
window.location.reload() if they differ from what the iframe loaded with.

This is the in-app equivalent of the hard-refresh workaround (Ctrl+F5)
that was given to the customer in ES-322.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
sdk.cma.appInstallation in the Page SDK context only exposes
getForOrganization, not get. Switch to getForOrganization and find
the matching installation by spaceId + environmentId before comparing
parameters to sdk.parameters.installation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@mgoudy91 Mitch Goudy (mgoudy91) force-pushed the fix/link-checker-stale-params-es-322 branch from 829b3ae to 20fac59 Compare June 17, 2026 22:33

@mgoudy91 Mitch Goudy (mgoudy91) 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.

Raised one issue around the JSON.stringify comparison being key-order-sensitive, which risks spurious reloads on every tab restore.

item.sys.space.sys.id === sdk.ids.space &&
item.sys.environment.sys.id === sdk.ids.environment
);
if (JSON.stringify(match?.parameters) !== JSON.stringify(sdk.parameters.installation)) {

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.

JSON.stringify comparison is key-order-sensitive — if the CMA response serializes object keys in a different order than the original SDK snapshot (common when two independent serialization paths are involved), this will produce a false mismatch and trigger a spurious reload on every tab restore. Consider a stable approach, e.g. sorting keys before stringifying or using a lightweight deep-equal utility:

const stableStringify = (obj: unknown) => JSON.stringify(obj, Object.keys(obj as object).sort());
if (stableStringify(match?.parameters) !== stableStringify(sdk.parameters.installation)) {

Or import a deepEqual helper if one is already available in the project.

…nsensitive deepEqual

Addresses Mitch's review: JSON.stringify is key-order-sensitive so a CMA
response with the same params in a different key order would spuriously
reload on every tab restore. Adds deepEqual helper and a dedicated test
covering the out-of-order key case. Also fixes the existing no-reload test
which was comparing mismatched fixtures and would have triggered reload.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@david-shibley-contentful david-shibley-contentful left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch — JSON.stringify is key-order-sensitive. Replaced it with a recursive deepEqual helper that sorts keys before comparing. Also added a dedicated test that passes the same params in reverse key order and asserts no reload. While I was in there I also fixed the existing no-reload test — its CMA mock was returning { selectedContentTypeIds: ['article'] } while sdk.parameters.installation was {}, so it would have triggered a reload under any correct implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants