mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 00:12:18 +00:00
Stop insights sub-pages from shifting after first paint
Weight, blood pressure and pulse painted no stat strip until their read landed, so the read strip and chart jumped down a card's height; the strip now holds its place with the skeleton the HealthKit pages already used, shared from the strip itself. The tab strip's scroll arrows render from the start and only hide while the row fits, instead of mounting once it measured as overflowing and shoving every pill sideways. The sleep page shows the stage chart's skeleton while loading rather than a 'no stage data yet' card. Load shift on weight, blood pressure and pulse drops from 0.3 to under 0.01.
This commit is contained in:
1 parent
3e1f630fa1
commit
4d18c4e101
9 files changed
+188
-72
No files matched your search
@@ -618,3 +618,23 @@ describe("<InsightsTabStrip> — pill row clip box (v1.16.8)", () => {
|
||||
expect(scroller).toContain("-mx-1");
|
||||
});
|
||||
});
|
||||
|
||||
describe("<InsightsTabStrip> — scroll arrows hold their slot", () => {
|
||||
it("renders both arrows before the row is measured, hidden but in place", () => {
|
||||
// Mounting the arrows only once the row measured as overflowing shifted
|
||||
// every pill sideways right after first paint (a layout shift on every
|
||||
// insights page). They render from the start and only hide.
|
||||
const html = render(<InsightsTabStrip />);
|
||||
for (const slot of [
|
||||
"insights-tab-strip-scroll-left",
|
||||
"insights-tab-strip-scroll-right",
|
||||
]) {
|
||||
const tag = html.match(
|
||||
new RegExp(`<button[^>]*data-slot="${slot}"[^>]*>`),
|
||||
);
|
||||
expect(tag?.[0]).toBeDefined();
|
||||
expect(tag?.[0]).toContain("invisible");
|
||||
expect(tag?.[0]).toContain('tabindex="-1"');
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,40 @@
|
||||
import { describe, it, expect, vi } from "vitest";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
|
||||
import { I18nProvider } from "@/lib/i18n/context";
|
||||
|
||||
/**
|
||||
* While the analytics read is in flight the stage chart holds its place with
|
||||
* a skeleton. Painting the "no stage data yet" card first said something
|
||||
* untrue and pushed the duration chart down when the bar replaced it.
|
||||
*/
|
||||
|
||||
const state = { isLoading: true, data: undefined as unknown };
|
||||
|
||||
vi.mock("@/lib/queries/use-analytics-query", () => ({
|
||||
useAnalyticsQuery: () => state,
|
||||
}));
|
||||
vi.mock("@/hooks/use-auth", () => ({
|
||||
useAuth: () => ({ isAuthenticated: true, user: { timezone: "UTC" } }),
|
||||
}));
|
||||
vi.mock("@/hooks/use-insights-layout-prefs", () => ({
|
||||
useInsightsLayoutPrefs: () => ({ compareBaseline: "none" }),
|
||||
}));
|
||||
vi.mock("../sleep-duration-chart", () => ({
|
||||
SleepDurationChart: () => <div data-slot="duration-chart" />,
|
||||
}));
|
||||
|
||||
import { SleepOverview } from "../sleep-overview";
|
||||
import en from "../../../../messages/en.json";
|
||||
|
||||
describe("SleepOverview — loading", () => {
|
||||
it("paints a skeleton, not the 'no stage data' card, while loading", () => {
|
||||
const html = renderToStaticMarkup(
|
||||
<I18nProvider initialLocale="en">
|
||||
<SleepOverview />
|
||||
</I18nProvider>,
|
||||
);
|
||||
expect(html).not.toContain(en.insights.sleep.stages.unavailable);
|
||||
expect(html).toContain('data-slot="duration-chart"');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user