Skip to content

Oracle tests, a shared core, React 19, and fixes for the open issues - #215

Merged
KyleAMathews merged 5 commits into
masterfrom
oracles-and-issue-cleanup
Nov 30, 2026
Merged

KyleAMathews merged 5 commits into
masterfrom
oracles-and-issue-cleanup

Conversation

@KyleAMathews

@KyleAMathews KyleAMathews commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Summary

This PR closes the react-headroom backlog. All scroll behavior moves into one framework-free controller, src/core.js. The <Headroom> component and a new useHeadroom hook are thin views over that controller. Oracle tests from @tanstack/oracles check each documented promise. They cover the controller, the first render on a server and the published package.

The result fixes the open bugs, adds the requested options and supports React 16.9 to 19. Ten high-effort code reviews found more defects. For each behavior defect, the oracle failed on the unchanged code before the fix. The package is now about 2.5 kB gzipped, down from about 4 kB in 3.2.1, and has no runtime dependencies.

How the change works

One controller. The controller listens to the scroller and decides the header state once per animation frame. A ResizeObserver on the border box tracks the header height. The header state is unfixed, pinned or unpinned. The component and the hook only render what the controller reports. Each kind of scheduled work has one pending animation frame. The controller cancels that frame when it detaches or unmounts.

The parent. Any window names its page, and so do its document, its root element and its body. An iframe's window also names its page. A body parent follows the body when the body has more to scroll than its page, and the page otherwise. The controller reads that again on each frame. It reads no styles. Earlier rules that read the overflow styles failed on real pages in Chrome, for example on a body with its default margin.

Three oracles.

  • test/headroom.oracle.js states each behavior promise as a law, with its source: the docs, a commit that states an intent, WCAG 2.2, or a maintainer decision. It generates histories over 16 page layouts. The histories contain scrolls, prop changes, resizes, focus, batched instance calls, overscroll, StrictMode and pending work at unmount. An independent model predicts what the header must show after each step.
  • test/headroom-server.oracle.js renders the component and the hook on a server with no window, and checks that the first render shows the header in place.
  • test/headroom-package.oracle.js builds and packs the package, and checks the tarball. It checks the ES2019 syntax, the CommonJS and ES module entry points and 'use client'. It also checks that there are no dependencies, and it checks tree-shaking, the file list and a 2,600 byte size budget.

Two runs of the behavior oracle. The jsdom run uses stand-ins for layout, scroll events and ResizeObserver. The gap check mutates the code in that run. The Chrome run (pnpm test:oracles:chrome) plays the same histories in the installed Chrome through Playwright. In the Chrome run, the layout, the scroll events, the computed styles and the ResizeObserver notifications are Chrome's own. The Chrome run found defects that the jsdom stand-ins hid. The oracle library runs only in Node, so the Chrome run keeps the oracle in Node and sends each history to the page. TanStack/oracles#49 asks for direct browser support.

The hook gives the same state to a header that you render yourself:

const { state, animated, transitionMs, ref } = useHeadroom({ pinStart: 100 })
return (
  <header
    ref={ref}
    className={`site-header site-header--${state}`}
    style={{ transition: animated ? `transform ${transitionMs}ms` : 'none' }}
  >
    …
  </header>
)

What changes for users

Fixed behavior

New options

Package changes for reviewers

  • The build targets browserslist defaults in ES2019 syntax, so webpack 4 parses it. The build no longer gives ES5 output for IE 11.
  • An ES module build ships in dist/esm, with the module field and "sideEffects": false. A bundle that imports only useHeadroom drops the component.
  • The raf dependency is gone. The package has no runtime dependencies.
  • The component moves to src/Headroom.js. src/index.js re-exports the component and the hook.
  • The React peer range is ^16.9.0 || ^17 || ^18 || ^19, not ^16.3.0. CI runs every oracle under React 16.9, 17, 18 and 19.
  • Headroom.defaultProps is gone. The defaults apply in render.

Behavior changes for reviewers

  • With pin, the header is unfixed at or above pinStart. Before, it stayed fixed and covered the element above it.
  • A scroll up never moves an unfixed header.
  • pin(), unpin() and unfix() do nothing when they name the current state, while pin or disable is set, or after unmount.
  • A header that mounts past its region starts hidden.
  • The region where a scroll up shows the header includes pinStart.
  • Until the controller measures the header element, the header is 0px tall. This case occurs when the ref of useHeadroom attaches after mount.
  • transitionMs changes only with a slide.
  • Inline styles no longer include the -webkit-, -ms-, -moz- or -o- prefixes.
  • This PR removes the propTypes, the prop-types dependency and the shallowequal dependency. <Headroom> is a PureComponent that renders only when something that it shows changes.
  • This PR removes the Safari one-tick delay from 3.1.1.

Docs

Decisions and limits

  • The inline transition stays all, as in 3.2.1. It also animates a change of the header's own size.
  • The controller reads parent() at mount, on each re-render, and once per frame while it returns nothing. A scroller that changes without a re-render is not noticed.
  • A body parent whose layout switches while mounted, for example under a scroll lock, can move the header once.
  • A quirks-mode body that its styles make scrollable is not supported.
  • Without a ResizeObserver, only a resize of the main window remeasures the header. Every browser in the build targets has a ResizeObserver.

Evidence

  • Oracles: 42 properties in three files, 180 tests. All pass in jsdom under React 16.9, 17, 18 and 19. The behavior oracle also passes in Chrome, with 140 tests.
  • Gap check: The gap check makes 319 mutants of the owned code. A law rejects all 319 mutants.
  • RED before each fix: For each behavior defect in this PR, the oracle failed on the unchanged code. Each review round has a ledger of its findings and their outcome.
  • Real browsers: The Chrome run killed three earlier stand-in mistakes as mutants. A hand test in Safari 27 showed no glitch with or without the one-tick delay.
  • CI: The jobs run on Node 24 only, because pnpm 11 needs Node 22.13 or later. Other jobs run the oracles under React 16.9, 17 and 19, the Chrome run, and the gap check.

Where to start in the diff

  • src/core.js holds all behavior. src/shouldUpdate.js decides what one frame does.
  • src/Headroom.js and src/useHeadroom.js are the two views. src/index.js re-exports them.
  • test/headroom.oracle.js holds the behavior laws. test/headroom-oracle-harness.js holds the history grammar and the model. test/oracle-driver.js holds the drivers.
  • test/oracle-page-jsdom.js and test/oracle-page-chrome.js are the two pages. test/oracle-chrome.js runs the Chrome page through Playwright.
  • AGENTS.md tells coding agents how to work with the oracles.

Closes

Supersedes #163, #179, #183, #208, #214 and the dependabot yarn.lock PRs (#188, #189, #193, #198, #199, #201, #202, #209).

This pull request and its description were written by Isaac.

Move all scroll behavior into a framework-free controller (src/core.js) used by
both <Headroom> and a new useHeadroom hook, and test it with @tanstack/oracles:
20 laws over generated histories, checked against an independent model for the
component and the hook, under React 18 and 19, with a mutation gap check
(290 of 291 mutants killed; the remaining one is a CLI timeout).

Fixes the header that could stay hidden after a flick at the top, double
onUnfix, pin ignored on mount, listeners that did not follow `parent`,
callbacks after unmount, overscroll at the bottom showing the header, focus
inside a hidden header, and the wrapper height not tracking the header.

Adds React 19 support, useHeadroom, unpinnedOffset, classNames,
matchScrollSpeed, wrapper state classes, headroom--bottom, and a
wrapperStyle.height override. Removes propTypes, vendor prefixes and the
Safari one-tick delay, which Safari 27 no longer needs. Ships only dist/ and
starts the build with 'use client'.

Moves the toolchain to Babel 7, ESLint 9, Vitest, pnpm and GitHub Actions, and
adds a README, CHANGELOG, the headroom.js credit, and an AGENTS.md block.

Co-authored-by: Isaac <no-reply@databricks.com>
This was referenced Nov 12, 2026
KyleAMathews and others added 4 commits November 12, 2026 10:16
Two high-effort code reviews and their evaluation, each finding turned into
an oracle law or history first (RED on the previous commit), then fixed:

- No crash when a queued frame outlives its scroller or header (R1, R2).
- unpinnedOffset negates any CSS length, including calc(), var() and 0 (R4, T9).
- The page's visible height excludes a horizontal scrollbar, and up to 1px
  past either end is in bounds (T3, R5).
- Attaching to a scroller (mount, parent change, re-enable) measures from its
  position and hides a header already past its region (R6, T1).
- The header region for showing includes pinStart (R7); a frame after a
  pause counts as one frame for matchScrollSpeed (T2); document,
  documentElement and body name the page again (T4).
- Work law W: one pending frame per job, cancelled on detach and unmount;
  re-renders with the same props do nothing; idle frames call no setState.
  The core is rewritten around it, <Headroom> is a PureComponent over what
  it shows, and shallowequal is dropped.

Oracle: 28 properties, 117 tests, React 18 and 19; gap check 299/299 mutants
killed. CI runs on Node 24 only (pnpm 11 needs Node 22.13+).

Co-authored-by: Isaac <no-reply@databricks.com>
…k the build

Behavior fixes, each shown failing in the oracle before the change:
- Height tracking follows padding and border changes (border-box
  ResizeObserver); a new tag no longer strands height tracking and focus.
- Attaching to a parent at or above pinStart unfixes a fixed header.
- Any window, its document, root and body name its page; a body parent
  follows the body when it has more to scroll than its page.
- Quirks-mode pages read the viewport from the scrolling element.
- pin(), unpin() and unfix() do nothing after unmount; batched calls no
  longer compare with stale React state.
- useHeadroom returns animated and transitionMs and re-renders only when
  they or state change; an unmeasured header is 0px tall.
- transitionMs changes only with a slide; negative numeric offsets work.

Package: modern targets that webpack 4 still parses, an ES module build
with sideEffects false, no runtime dependencies (raf removed), the
component in its own module, a clean build, React 16.9 and later.

Oracles: every law over every scroller and page layout; the first render
on a server; the packed tarball (syntax, entry points, 'use client', no
dependencies, tree-shaking, contents, size); hook parity; React 16.9, 17,
18 and 19 in CI; and a Chrome run that plays the behavior oracle's
histories in real Chrome through Playwright. Gap check: 319 of 319 killed.

Co-authored-by: Isaac <no-reply@databricks.com>
- Pin @tanstack/oracles and @tanstack/eslint-plugin-oracles to b3dbde0,
  the newest commit with a pkg.pr.new build (main's tip, 0175017, only
  changes CI and was not published).
- AGENTS.md: the oracles block is now template 4.
- Skill pointers: oracles-start is replaced by oracles-explore; the
  oracles-setup description is refreshed.
- src/core.js: attach() no longer returns schedule()'s result. Every
  caller drops it and it is always undefined, so the new gap check's
  return-undefined mutant could not be told apart. The lookup itself
  stays covered: its delete-call mutant is killed by the ref-parent
  histories.

Gap check (seed 1): 332 mutants, 332 killed, 0 gaps.

Co-authored-by: Isaac <no-reply@databricks.com>
…leanup

Fix (oracle first): inside a transformed ancestor (transform: scale())
the header measured its on-screen height, so the wrapper reserved too
little space and the header region ended early. measure() now reads the
border-box height from the computed style: the header's own CSS px,
fractions included. A new history dimension (an ancestor's scale) failed
65 tests on the old code in jsdom and in Chrome; box-sizing is varied too.

Release:
- CHANGELOG retitled 4.0.0, with a Breaking section.
- TypeScript types (index.d.ts), checked by test/types with tsc.
- prepack builds; `release` replaces publish-patch (npm version first).
- Package size budget 2,700 bytes (decision 2026-11-30).
- New Vite demo in demo/ (workspace package) replaces the Gatsby 1 www/;
  demo:deploy publishes it to gh-pages.
- Removed .npmignore and directories.example.

Tooling: CI actions bumped (checkout, setup-node, upload-artifact v7,
pnpm/action-setup v6), permissions, concurrency and timeouts; unit tests
scoped to test/; lint covers the whole repo; a format check in `pnpm test`.

Oracles: the speed law no longer passes histories with inline styles off
(it no longer generates them); the defaults law's styles are scoped to the
component; the work law bounds lookups exactly instead of exempting resize
and swap steps; authorities cite durable sources (5cf1093 for 3.2.1's docs
and source) instead of review IDs and directives.

Gap check (seed 1): 342 mutants, 342 killed, 0 gaps. Chrome: 766 passed.

Co-authored-by: Isaac <no-reply@databricks.com>
@KyleAMathews
KyleAMathews merged commit b3d0d06 into master Nov 30, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant