fix(lazy-loader): bump default rootMargin to 2000px so dedicated dashboard pages load without user scroll#2465
Merged
Conversation
Agent-Logs-Url: https://github.com/Hack23/riksdagsmonitor/sessions/da8b2e37-d5ba-434b-8dac-6e1c0182ac88 Co-authored-by: pethers <1726836+pethers@users.noreply.github.com>
…-viewport containers Agent-Logs-Url: https://github.com/Hack23/riksdagsmonitor/sessions/da8b2e37-d5ba-434b-8dac-6e1c0182ac88 Co-authored-by: pethers <1726836+pethers@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
pethers
May 13, 2026 20:42
View session
Contributor
🔍 Lighthouse Performance Audit
📥 Download full Lighthouse report Budget Compliance: Performance budgets enforced via |
Contributor
🏷️ Automatic Labeling SummaryThis PR has been automatically labeled based on the files changed and PR metadata. Applied Labels: documentation,html-css,javascript,translation,rtl,testing,size-xl,news Label Categories
For more information, see |
… pages Agent-Logs-Url: https://github.com/Hack23/riksdagsmonitor/sessions/1336d408-7984-44f1-97e3-ea867546d498 Co-authored-by: pethers <1726836+pethers@users.noreply.github.com>
Contributor
🔍 Lighthouse Performance Audit
📥 Download full Lighthouse report Budget Compliance: Performance budgets enforced via |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Plan
Live regression: on dedicated
/dashboards/<name>.htmlpages the single dashboard container sits ~1 156 px below the fold of a 720 px viewport. With the previousrootMargin: '200px', theIntersectionObserverinlazy-loader.tsnever fired without user scroll → Chart.js / D3 / PapaParse were never registered → all charts rendered empty and dashboards' init() failed with misleading error fallbacks ("Cannot access 'o' before initialization", "Unable to load risk assessment data from CIA Platform"). The per-chart Cypress suite did not catch this becausecy.visitDashboard()unconditionallyscrollIntoView()s the container.Fix
src/browser/lazy-loader.tsDEFAULT_ROOT_MARGIN = '2000px'(≈ 2 viewport heights — covers the ~1 156 px below-fold offset on every dedicated dashboard page) andDEFAULT_THRESHOLD = 0.01constants.initLazyDashboards()now defaults to these.requestAnimationFrameafter registration, the loader probes each container'sgetBoundingClientRect()against the configuredrootMarginand synthesises a load for anything that would intersect — fires the loader exactly once even in browser/iframe contexts that don't deliver an initial IO entry without user-driven scroll.parseRootMarginPx()helper.tests/lazy-loader.test.jsDEFAULT_ROOT_MARGIN = "2000px"/DEFAULT_THRESHOLD = 0.01regression contract.initLazyDashboards()passes those values to theIntersectionObserverby default.parseRootMarginPx()unit tests covering px / negative / percentage / undefined / empty / malformed inputs.npx vitest run tests/lazy-loader.test.js).cypress/e2e/dashboards-no-scroll.cy.js(new spec — would have caught the live regression)parties,committees,coalitions,election-cycle,seasonal-patterns,pre-election,anomaly-detection,ministers,risk).main-*.jsbundle is served (no/src/browser/main.tsdev path);window.Chart+window.d3register within 15 s without any scroll; no visible.error-message/[role="alert"]containing user-facing error text is rendered (skips empty placeholder banners like risk.html's#earlyWarnings).vite preview(npx cypress run --spec cypress/e2e/dashboards-no-scroll.cy.js).npx tsc --noEmit -p tsconfig.browser.json→ clean.Geometry that proves the fix