Skip to content

Add support for scrollMargin option for intersection observers#753

Merged
thebuilder merged 2 commits into
mainfrom
codex/add-support-for-scrollmargin-in-intersectionobserver
Jul 10, 2026
Merged

Add support for scrollMargin option for intersection observers#753
thebuilder merged 2 commits into
mainfrom
codex/add-support-for-scrollmargin-in-intersectionobserver

Conversation

@thebuilder

@thebuilder thebuilder commented Jul 9, 2026

Copy link
Copy Markdown
Owner

Motivation

  • Add support for a scrollMargin option to allow margins around nested scroll containers (and the root if it's a scroll container) to be considered by the observer.
  • Propagate this option through the public types, hooks, component props, observer creation logic, test utilities, and Storybook so consumers can configure and visualize it.

Description

  • Introduce IntersectionObserverInitWithOptions and extend public IntersectionOptions to include scrollMargin, trackVisibility, and delay where applicable.
  • Wire scrollMargin into observe() and optionsToId() so observers are keyed and created correctly, and make observers recreate when scrollMargin changes in InView and hooks.
  • Update the IntersectionObserver mock in test-utils.ts to expose scrollMargin so unit tests can assert the option is passed.
  • Update README and Storybook stories/argTypes to document and showcase the scrollMargin option.

Fixes #749

@vercel

vercel Bot commented Jul 9, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
react-intersection-observer Ready Ready Preview, Comment Jul 9, 2026 7:28am

@bolt-new-by-stackblitz

Copy link
Copy Markdown

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@pkg-pr-new

pkg-pr-new Bot commented Jul 9, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/react-intersection-observer@753

commit: a69589e

@thebuilder thebuilder merged commit 143c57e into main Jul 10, 2026
15 checks passed
@thebuilder thebuilder deleted the codex/add-support-for-scrollmargin-in-intersectionobserver branch July 10, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for scrollMargin field

1 participant