Open
Conversation
Coverage report for library
Test suite run success473 tests passing in 23 suites. Report generated by 🧪jest coverage report action from e0d735d |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a new Angular service to track the current document root font size (rem baseline) at runtime, primarily to support components that need accurate px↔rem conversions across dynamic theme/layout changes and microfrontend setups.
Changes:
- Added
CpsRootFontSizeServiceusing aResizeObserveron a shared “1rem” sentinel element to react to root font-size changes. - Added Jest unit tests for browser/SSR behavior and for the
CPS_ROOT_FONT_SIZE_SERVICEinjection token. - Updated the API generator to skip writing empty per-module JSON outputs.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| projects/cps-ui-kit/src/public-api.ts | Exports the new root font-size service from the library public surface. |
| projects/cps-ui-kit/src/lib/services/cps-root-font-size/cps-root-font-size.service.ts | Implements root font-size tracking + injection token for override/disable scenarios. |
| projects/cps-ui-kit/src/lib/services/cps-root-font-size/cps-root-font-size.service.spec.ts | Adds unit coverage for browser mode, SSR mode, sentinel reuse, and token resolution. |
| api-generator/api-generator.js | Skips emitting JSON files for empty docs modules. |
Playwright test resultsDetails
|
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.
Overview
Implemented
CpsRootFontSizeServicethat tracks the application's current root font size.The service uses a
ResizeObserverstrategy to reliably detect root font-size changes on a sentinel element (<div style="width:1rem;height:0">).Its pixel width mirrors
1rem. Any root font-size change caused by CSS class toggles, stylesheet rules, direct JS assignment, or viewport resize (e.g.font-size: 1.5vw) changes the sentinel's computed width, firing the observer.The cached value is stored in a signal and is only updated when the actual font-size value changes, preventing spurious updates.
In microfrontend environments the sentinel element is keyed by a known DOM attribute (
data-cps-root-font-size-sentinel) and reused if already present, so only one sentinel node exists per document regardless of how many instances of this service are created. The sentinel is intentionally never removed from the DOM - it is a lightweight, invisible element and removing it could silently break any other live service instance still observing it.Only active in browser environments. Under SSR the
fontSizesignal is initialized to16(the standard browser default) and no DOM observers are created.The injection token
CPS_ROOT_FONT_SIZE_SERVICEfor the root font size service is created. By default it resolves to the singletonCpsRootFontSizeService.Consumer apps can override it to supply a custom subclass or to provide
nullto disable dynamic tracking entirely.Injecting
CPS_ROOT_FONT_SIZE_SERVICEin consumer apps should be preferred over injecting the service class directly, as it allows them to override the implementation behavior.Follow-up scope
Release notes:
CpsRootFontSizeService