Skip to content

Commit ca64cf2

Browse files
authored
Merge pull request #10 from RamssCR/fix/metrics-issues
Fix/metrics issues
2 parents d9c78af + e6bb4af commit ca64cf2

File tree

5 files changed

+35
-21
lines changed

5 files changed

+35
-21
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Changelog
2+
3+
All notable updates of this library will be documented on this file.
4+
5+
This format is based on [Keep a Changelog](https://keepachangelog.com/1.0.0/)
6+
and this project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [1.0.2] - 2025-08-12
9+
### Fixed
10+
- Corrected duplicated metrics on `getAccessibility`.
11+
- Fixed off-screen `web-vitals` changes.
12+
13+
## [1.0.1] - 2025-08-11
14+
### Fixed
15+
- Removed incorrect `Debugger` props on the `README` file.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "A tool for measuring and optimizing web vitals in React applications, including Lighthouse measurements like Accessibility, Best Practices and SEO.",
44
"module": "dist/vitals-tool.js",
55
"types": "dist/index.d.ts",
6-
"version": "1.0.1",
6+
"version": "1.0.2",
77
"type": "module",
88
"exports": {
99
".": {

src/components/debugger/DebugButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const DebugButton = ({ ...props }: ComponentProps<typeof Button>) => (
1111
<Button
1212
variant="none"
1313
size="icon"
14-
className="tw:rounded-full tw:border-2 tw:border-muted/90 tw:size-12 tw:p-3 tw:bg-tool-bg tw:shadow tw:absolute tw:bottom-4 tw:right-4 tw:z-1000"
14+
className="tw:rounded-full tw:border-2 tw:border-muted/90 tw:size-12 tw:p-3 tw:bg-tool-bg tw:shadow tw:fixed tw:bottom-4 tw:right-4 tw:z-1000"
1515
aria-label="Debug Button"
1616
{...props}
1717
>

src/helpers/getAccessibility.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,21 @@ export const getAccessibility = async (): Promise<Accessibility> => {
2727
}
2828
})
2929

30-
const total = result.violations.length + result.passes.length
31-
const score = total === 0
32-
? 100
33-
: Math.round((result.passes.length / total) * 100)
34-
35-
const details = result.violations.map((violation) => ({
36-
label: violation.id,
37-
value: 0
38-
}))
30+
const filteredResults = new Map<string, number>()
31+
result.violations.forEach(violation => filteredResults.set(violation.id, 0))
3932

40-
result.passes.forEach((pass) => {
41-
details.push({
42-
label: pass.id,
43-
value: 1
44-
})
33+
result.passes.forEach(pass => {
34+
if (!filteredResults.has(pass.id)) {
35+
filteredResults.set(pass.id, 1)
36+
}
4537
})
38+
39+
const details = Array.from(filteredResults, ([label, value]) => ({ label, value }))
40+
const score = details.length === 0
41+
? 100
42+
: Math.round(
43+
(details.filter(detail => detail.value === 1).length / details.length) * 100
44+
)
4645

4746
return {
4847
score,

src/helpers/getPerformance.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ export const normalizeScore = (name: string, value: number): number => {
2929
}
3030

3131
const listeners = {
32-
LCP: onLCP,
33-
CLS: onCLS,
34-
INP: onINP,
35-
FCP: onFCP,
36-
TTFB: onTTFB,
32+
LCP: (cb: (metric: Metric) => void) => onLCP(cb, { reportAllChanges: true }),
33+
CLS: (cb: (metric: Metric) => void) => onCLS(cb, { reportAllChanges: true }),
34+
INP: (cb: (metric: Metric) => void) => onINP(cb, { reportAllChanges: true }),
35+
FCP: (cb: (metric: Metric) => void) => onFCP(cb, { reportAllChanges: true }),
36+
TTFB: (cb: (metric: Metric) => void) => onTTFB(cb, { reportAllChanges: true }),
3737
}
3838

3939
/**

0 commit comments

Comments
 (0)