Repository navigation
Oracle tests, a shared core, React 19, and fixes for the open issues - #215
Merged
Merged
Conversation
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
Closed
Closed
Closed
Closed
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>
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.
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 newuseHeadroomhook 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
ResizeObserveron the border box tracks the header height. The header state isunfixed,pinnedorunpinned. 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.jsstates 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.jsrenders the component and the hook on a server with nowindow, and checks that the first render shows the header in place.test/headroom-package.oracle.jsbuilds 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 theResizeObservernotifications 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:
What changes for users
Fixed behavior
onUnfixno longer fires twice.pinapplies on mount. Withpin, the header is in place at or abovepinStart.parentchange moves the listeners. Aparent()that returns a ref, an empty value,document,document.documentElement,document.bodyor an iframe's window works (Parent example #110).overflow-x: hidden. Quirks-mode pages read the viewport from the page's scrolling element.pinStartgoes back in place at once.pinStartincluded.pin(),unpin()andunfix()on an unmounted component do nothing.tagno longer leaves the height and the focus on the old element.unpinnedOffsetaccepts any CSS length, includingcalc(),var(),0and negative numbers.matchScrollSpeed, a flick after a pause slides fast. A gap of more than 100 ms counts as one frame.dist/(Unknown plugin "transform-undefined-to-void" #129). Each entry file starts with'use client'(Super expression must either be null or a function, not undefined #211).New options
useHeadroom(Feature use headroom #183). It returnsstate,animated,transitionMsandref. It re-renders only whenstate,animatedortransitionMschanges.unpinnedOffset(Support partial visibility #115, Allow optional sticky subheader #163, Support manual pin/unpin #116).classNames(Add possibility to set class names #104, using react-themeable with CSS-loader #48).headroom-wrapper--<state>classes on the wrapper (Set className on outer <div> instead #108, ClassName in wrapperClassName #152).headroom--bottomclass (Support of headroom--bottom #107).matchScrollSpeed(Measure scroll speed and set CSS transition to match #94).heightinwrapperStylereplaces the measured height (Let consumers override wrapper inlineheightstyle #179).Package changes for reviewers
defaultsin ES2019 syntax, so webpack 4 parses it. The build no longer gives ES5 output for IE 11.dist/esm, with themodulefield and"sideEffects": false. A bundle that imports onlyuseHeadroomdrops the component.rafdependency is gone. The package has no runtime dependencies.src/Headroom.js.src/index.jsre-exports the component and the hook.^16.9.0 || ^17 || ^18 || ^19, not^16.3.0. CI runs every oracle under React 16.9, 17, 18 and 19.Headroom.defaultPropsis gone. The defaults apply in render.Behavior changes for reviewers
pin, the header is unfixed at or abovepinStart. Before, it stayed fixed and covered the element above it.pin(),unpin()andunfix()do nothing when they name the current state, whilepinordisableis set, or after unmount.pinStart.useHeadroomattaches after mount.transitionMschanges only with a slide.-webkit-,-ms-,-moz-or-o-prefixes.propTypes, theprop-typesdependency and theshallowequaldependency.<Headroom>is aPureComponentthat renders only when something that it shows changes.Docs
CHANGELOG.mdrecords every change for 3.3.0 (Please add a Changelog.md or similar #170, Note on 1.8.3 #79).Decisions and limits
all, as in 3.2.1. It also animates a change of the header's own size.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.ResizeObserver, only a resize of the main window remeasures the header. Every browser in the build targets has aResizeObserver.Evidence
Where to start in the diff
src/core.jsholds all behavior.src/shouldUpdate.jsdecides what one frame does.src/Headroom.jsandsrc/useHeadroom.jsare the two views.src/index.jsre-exports them.test/headroom.oracle.jsholds the behavior laws.test/headroom-oracle-harness.jsholds the history grammar and the model.test/oracle-driver.jsholds the drivers.test/oracle-page-jsdom.jsandtest/oracle-page-chrome.jsare the two pages.test/oracle-chrome.jsruns the Chrome page through Playwright.AGENTS.mdtells coding agents how to work with the oracles.Closes
Supersedes #163, #179, #183, #208, #214 and the dependabot
yarn.lockPRs (#188, #189, #193, #198, #199, #201, #202, #209).This pull request and its description were written by Isaac.