From 90fa4c6ee3a98ba45529a4e923a29083c8f91adb Mon Sep 17 00:00:00 2001 From: ChristopherPHolder Date: Fri, 13 Nov 2026 20:46:32 +0100 Subject: [PATCH] docs: add a soft navigations integration page Shows how to use @push-based/lighthouse-soft-navigation in a flow file, and links to its docs for how soft navigation steps are measured. --- packages/docs/src/app/docs/nav.ts | 13 +- .../content/cli/lighthouse-configuration.md | 2 + .../content/integrations/soft-navigations.md | 120 ++++++++++++++++++ 3 files changed, 132 insertions(+), 3 deletions(-) create mode 100644 packages/docs/src/content/integrations/soft-navigations.md diff --git a/packages/docs/src/app/docs/nav.ts b/packages/docs/src/app/docs/nav.ts index 8c7b74b1..2e93f1d5 100644 --- a/packages/docs/src/app/docs/nav.ts +++ b/packages/docs/src/app/docs/nav.ts @@ -42,9 +42,7 @@ export const SECTION_ICONS: Record = { 'M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z', ], // Book - resources: [ - 'M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H20v20H6.5a2.5 2.5 0 0 1 0-5H20', - ], + resources: ['M4 19.5v-15A2.5 2.5 0 0 1 6.5 2H20v20H6.5a2.5 2.5 0 0 1 0-5H20'], }; export const DOCS_NAV: DocSection[] = [ @@ -168,6 +166,15 @@ export const DOCS_NAV: DocSection[] = [ 'Generators and an executor that make user flows a first-class target in an Nx workspace.', load: md(() => import('../../content/integrations/nx-plugin.md')), }, + { + slug: 'soft-navigations', + title: 'Soft navigations', + description: + 'Measure single page app route changes as navigation steps with @push-based/lighthouse-soft-navigation.', + load: md( + () => import('../../content/integrations/soft-navigations.md'), + ), + }, ], }, { diff --git a/packages/docs/src/content/cli/lighthouse-configuration.md b/packages/docs/src/content/cli/lighthouse-configuration.md index d947b2ea..2b81c017 100644 --- a/packages/docs/src/content/cli/lighthouse-configuration.md +++ b/packages/docs/src/content/cli/lighthouse-configuration.md @@ -80,6 +80,8 @@ export default { }; ``` +The [soft navigations integration](/docs/integrations/soft-navigations) shows this config in a complete flow. + > [!IMPORTANT] > To add your own artifacts on top of the default config, set `extends: 'lighthouse:default'` yourself. Without it the config counts as complete, and the report only contains the audits it lists. Lighthouse treats a config without `extends` the same way. diff --git a/packages/docs/src/content/integrations/soft-navigations.md b/packages/docs/src/content/integrations/soft-navigations.md new file mode 100644 index 00000000..baa710e6 --- /dev/null +++ b/packages/docs/src/content/integrations/soft-navigations.md @@ -0,0 +1,120 @@ +A soft navigation is a route change that updates the URL and the content without loading a new document, like a single page app does on a link click. Stock Lighthouse can't measure one as a navigation step: it waits for a page load that never comes and fails with `NO_FCP`. + +[`@push-based/lighthouse-soft-navigation`](https://push-based.github.io/lighthouse-soft-navigation/) is a Lighthouse config that measures it as a navigation step, from the click, with FCP, LCP and a Performance score. Pass it as the config of a flow, and its soft navigation steps show up in every user-flow report next to page loads, timespans and snapshots. + +This page covers the user-flow setup. How soft navigation steps are recognised and measured, and their limits, are in the [lighthouse-soft-navigation docs](https://push-based.github.io/lighthouse-soft-navigation/). + +> [!IMPORTANT] +> Requires user-flow 0.21.6 or newer. Older versions add `extends: 'lighthouse:default'` to the config, so the first step fails with `TypeError: Expected object but got string`. They also run Chrome 148, where a soft navigation step loses TBT, TTI and its Performance score. + +## Installation + +```bash tab="npm" +npm install --save-dev @push-based/user-flow @push-based/lighthouse-soft-navigation +``` + +```bash tab="yarn" +yarn add --dev @push-based/user-flow @push-based/lighthouse-soft-navigation +``` + +```bash tab="pnpm" +pnpm add -D @push-based/user-flow @push-based/lighthouse-soft-navigation +``` + +The gatherers of the package extend the stock gatherers of the Lighthouse they import, so user-flow and the package have to share one copy of Lighthouse. Both depend on `lighthouse@^13.6.0`, so it is installed once. `npm ls lighthouse` shows a single version. + +## Flow file + +```typescript title="user-flows/checkout.uf.mts" +import { softNavigationConfig } from '@push-based/lighthouse-soft-navigation'; +import type { UserFlowProvider } from '@push-based/user-flow'; + +const observed = { throttlingMethod: 'devtools' } as const; + +export default { + flowOptions: { name: 'Checkout', config: softNavigationConfig() }, + interactions: async ({ flow, page, collectOptions }) => { + // A page load, measured by stock Lighthouse. + await flow.navigate(collectOptions.url); + + // A soft navigation. + await flow.navigate(async () => { + await page.click('a.product-link'); + }, observed); + + // The same with startNavigation/endNavigation. + await flow.startNavigation(observed); + await page.click('a.checkout-link'); + await flow.endNavigation(); + }, +} satisfies UserFlowProvider; +``` + +```sh +npx user-flow collect --url https://example.com --ufPath ./user-flows +``` + +- The config goes in `flowOptions.config`. `collect.config` and `collect.configPath` in `.user-flowrc.json` and `--configPath` take JSON, which can't hold the gatherer and audit classes of the package. +- A soft navigation step is a navigation step whose interaction stays in the document. See [Soft navigation steps](https://push-based.github.io/lighthouse-soft-navigation/docs/guides/steps). +- A soft navigation step passes `throttlingMethod: 'devtools'` or `'provided'`, since simulated throttling needs a document request. See [Throttling](https://push-based.github.io/lighthouse-soft-navigation/docs/guides/throttling). + +## Settings + +`softNavigationConfig()` returns a [complete config](/docs/cli/lighthouse-configuration#complete-configs), so user-flow runs it as written and only takes `settings` from the project. Settings for every flow go in `collect.config` of `.user-flowrc.json`, or in the file passed with `--configPath`: + +```json title=".user-flowrc.json" +{ + "collect": { + "config": { + "settings": { + "throttlingMethod": "devtools", + "onlyCategories": ["performance"] + } + } + } +} +``` + +With `throttlingMethod` set for the project, the steps don't need to pass it. Page loads then run with DevTools throttling too; [Throttling](https://push-based.github.io/lighthouse-soft-navigation/docs/guides/throttling#for-the-whole-flow) explains the trade-off. + +Settings for one flow go in its config, through `softNavigationConfig`. They take precedence over the settings of the project: + +```typescript +config: softNavigationConfig({ + extends: 'lighthouse:default', + settings: { onlyCategories: ['performance'] }, +}), +``` + +## Recordings + +A Chrome DevTools recording replayed with `createUserFlowRunner` measures a soft navigation with `startNavigation` and `endNavigation` steps. The throttling method goes in `stepOptions`: + +```json title="products.replay.json" +{ + "title": "Open a product", + "steps": [ + { + "type": "startNavigation", + "stepOptions": { "throttlingMethod": "devtools" } + }, + { + "type": "click", + "selectors": [["a.product-link"]], + "offsetX": 5, + "offsetY": 5 + }, + { "type": "endNavigation" } + ] +} +``` + +See [DevTools Recorder exports](/docs/user-flows/recorder-exports) for replaying recordings. + +## Reports + +A soft navigation step is a navigation step, so the HTML, JSON and Markdown reports show it like a page load: gather mode `navigation`, with a Performance score. The `soft-navigation` audit tells the two apart. See [Reading the results](https://push-based.github.io/lighthouse-soft-navigation/docs/guides/results). + +## Dry runs + +`--dryRun` fails for a flow that navigates with a callback or calls `startNavigation`, which every soft navigation does. The dry run stand-in doesn't support either yet; see [#355](https://github.com/push-based/user-flow/issues/355).