Skip to content

Commit da021c7

Browse files
committed
feat(null-children): Support for null children and null DOM node (#52)
* feat(null-children): Support for null children and null DOM node - Trigger invariant on observing if DOM node isn't found - Do nothing if user passes null/undefined as children - Handle re-renders from null/undefined to element children - Remove prop onlyOnce from API and its deprecation warning - Re-observing logic has been improved; no more unnecessary calls to observeElement/unobserveElement - Getting options is now a function for perf speed and transpilation output size - Removed duplicated test cases and solidified existing ones BREAKING CHANGE: Drop support for React < 16.3.2 * chore(release): 1.0.0-beta.0 * chore(errorReporter): added configurable error reporter * chore(release): 1.0.0-beta.1 * chore(readme): update docs about errorReporting
1 parent 37b20ff commit da021c7

24 files changed

+6150
-4629
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,3 @@ npm-debug.log*
33
yarn-error.log
44
lib
55
coverage
6-
docs/static
7-
docs/favicon*
8-
docs/*.html

.storybook/addons.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
import '@storybook/addon-options/register';
22
import 'storybook-readme/register';
33
import '@storybook/addon-actions/register';
4-
import '@storybook/addon-knobs/register';
4+
import '@storybook/addon-knobs/register';

.storybook/webpack.config.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
const path = require('path');
22

33
module.exports = {
4-
module: {
5-
rules: [
6-
{
7-
test: /\.css$/,
8-
loaders: ['style-loader', 'css-loader'],
9-
include: path.resolve(__dirname, '../'),
10-
},
11-
{
12-
test: /\.md$/,
13-
loaders: ['raw-loader'],
14-
},
15-
],
16-
},
4+
module: {
5+
rules: [
6+
{
7+
test: /\.css$/,
8+
loaders: ['style-loader', 'css-loader'],
9+
include: path.resolve(__dirname, '../'),
10+
},
11+
],
12+
},
1713
};

.travis.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
language: node_js
22
node_js:
3-
- "10"
4-
- "6"
3+
- "8"
4+
- "9"
55
cache: yarn
66
deploy:
77
local_dir: docs
88
provider: pages
99
skip_cleanup: true
10-
github_token: $GITHUB_TOKEN # Set in travis-ci.org dashboard
10+
github_token: $GITHUB_TOKEN # Set on travis-ci.org dashboard
1111
on:
12-
branch: master
13-
condition: '"$TRAVIS_JOB_NUMBER" == *.1'
14-
before_install: yarn global add greenkeeper-lockfile@1
12+
branch: master
13+
condition: '"$TRAVIS_JOB_NUMBER" == *.1'
1514
before_script:
16-
- greenkeeper-lockfile-update
17-
# true needs to be removed after https://github.com/conventional-changelog/conventional-github-releaser/pull/47 is fixed
18-
- 'if [[ -n "$TRAVIS_TAG" ]] && [[ "$TRAVIS_JOB_NUMBER" == *.1 ]]; then yarn run create-github-release || true; fi'
15+
- 'if [[ -n "$TRAVIS_TAG" ]] && [[ "$TRAVIS_JOB_NUMBER" == *.1 ]]; then yarn run create-github-release; fi'
1916
script:
2017
- yarn run lint
21-
- yarn test -- --ci --coverage
18+
- yarn test --ci --coverage
2219
- 'if [[ "$TRAVIS_JOB_NUMBER" == *.1 ]]; then yarn run build:storybook; fi'
23-
after_script: greenkeeper-lockfile-upload
2420
after_success:
2521
- bash <(curl -s https://codecov.io/bash)

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,28 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
<a name="1.0.0"></a>
6+
# [1.0.0](https://github.com/researchgate/react-intersection-observer/compare/v1.0.0-beta.0...v1.0.0) (2019-04-18)
7+
8+
9+
10+
<a name="1.0.0-beta.0"></a>
11+
# [1.0.0-beta.0](https://github.com/researchgate/react-intersection-observer/compare/v0.7.4...v1.0.0-beta.0) (2018-12-13)
12+
13+
14+
### Features
15+
16+
* **null-children:** Support for null children and null DOM node ([04de77e](https://github.com/researchgate/react-intersection-observer/commit/04de77e))
17+
18+
19+
### BREAKING CHANGES
20+
21+
* **null-children:** Drop support for React < 16.3.2
22+
23+
-
24+
25+
26+
527
<a name="0.7.4"></a>
628
## [0.7.4](https://github.com/researchgate/react-intersection-observer/compare/v0.7.3...v0.7.4) (2018-10-23)
729

README.md

Lines changed: 67 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<p align="center">
2-
<img alt="React Intersection Observer" src=".github/logo.svg" width="888">
2+
<img alt="React Intersection Observer" src=".github/logo.svg" />
33
</p>
44

55
<p align="center">
66
<a href="https://travis-ci.org/researchgate/react-intersection-observer"><img alt="Build Status" src="https://travis-ci.org/researchgate/react-intersection-observer.svg?branch=master"></a>
77
<a href="https://codecov.io/gh/researchgate/react-intersection-observer"><img alt="Codecov" src="https://img.shields.io/codecov/c/github/researchgate/react-intersection-observer.svg"></a>
88
<a href="https://www.npmjs.com/package/@researchgate/react-intersection-observer"><img alt="NPM version" src="https://img.shields.io/npm/v/@researchgate/react-intersection-observer.svg"></a>
9-
<a href="https://github.com/prettier/prettier"><img alt="styled with prettier" src="https://img.shields.io/badge/styled_with-prettier-ff69b4.svg"></a>
9+
<a href="https://www.npmjs.com/package/@researchgate/react-intersection-observer"><img alt="Dowloads per week" src="https://img.shields.io/npm/dw/@researchgate/react-intersection-observer.svg"></a>
1010
</p>
1111

1212
<br>
@@ -18,33 +18,32 @@ is fully declarative and takes care of all the imperative parts for you.
1818

1919
**React Intersection Observer** is good at:
2020

21-
* **reusing instances**: comparing the passed options
22-
* **performance**: chooses smartly when to re-render and when to re-observe
23-
* **being unopinionated**: how to handle visibility changes is left entirely up to the developer
24-
* **being intuitive**: looks like the Native API
25-
* **small size**: ~6.5kB before minification (> 3.5kB or less when [minified](https://babeljs.io/repl#?babili=true&browsers=&build=&builtIns=false&spec=false&loose=false&code_lz=JYWwDg9gTgLgBAJQKYEMDG8BmUIjgcilQ3wG4AoUSWOAbzk2ADsATAEQHkBZAOQhaRwAvgxx5CxGAFoWuMpXDR4zAG4oowFEyxiCq9Zu3yqSu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iMa_K2u_XqjMemC5ViFtpfdk28_sL2M-rxTvwe-0GwOoXAlEpHaQcA4gxAi1G0DIPNBakBSHYjL5gggiNSC8AIJgKvsRB2n2JImUEkLRDwBwGwNELxNEDwJUBzAQB2iwJumlMZqZuVEgE4skDOm2qjI-FKNKBqmknAKbltvoBoFoM0KVh1uvrOBKHQe6PgESCzvEJIgwJMn5Crguh9OfEwERvAIWP5MAK1jOJgPVMfDAM4uACokLugGAc7j-hIeQgdJgPWLEGUJKMwUfsAT6ADjaoEPmqFFtiPgXlVv6ifjWIoIujAJfiwIzszs4junhFJnuszK1Ipv7k_LyjLO4ZxIkDuhFDxoLG-J-CLL-ADvyGekpAbm4c5rERpNYfKt4dnmYTtkRhYX6vod3hHD4T1DsmkZkjnswS8oYbmsYe_qUQFnkOYVzPtsxIdjpMdonLYU0AAOoUL05MCKLKIr7F63p76s4V7WEh4nLtJIbjFJ4N4EYMGFyHAP7PrJxDiCBI5b4HTAhwKMCPRJRJCh4pFlb6Ta5tq9oe4PL4FzpPYg5JCTbTaOYPZA7PZJBs5_ZlaYD5bgYdjxBnZMHTgrijG3goRa6AEoC5TwBrYaJHKOxjoUDAmmD0DYGVS0hOhCAUBAA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=true&sourceType=module&lineWrap=false&presets=react%2Cbabili&prettier=false&targets=&version=6.26.0&envVersion=), ~1.3kB gzipped)
21+
- **reusing instances**: comparing the passed options
22+
- **performance**: chooses smartly when to re-render and when to re-observe
23+
- **being unopinionated**: how to handle visibility changes is left entirely up to the developer
24+
- **being intuitive**: looks like the Native API
2625

2726
<br>
2827

2928
<details>
3029
<summary><strong>Table of Contents</strong></summary>
3130

32-
* [Getting started](#getting-started)
33-
* [Installation](#installation)
34-
* [Inside your codebase](#inside-your-codebase)
35-
* [What does IntersectionObserver do?](#what-does-intersectionobserver-do)
36-
* [Why use this component?](#why-use-this-component)
37-
* [No bookkeeping](#no-bookkeeping)
38-
* [No extra markup](#no-extra-markup)
39-
* [Easy to adopt](#easy-to-adopt)
40-
* [Documentation](#documentation)
41-
* [Options](#options)
42-
* [Notes](#notes)
43-
* [Polyfill](#polyfill)
44-
* [IntersectionObserver's Browser Support](#intersectionobservers-browser-support)
45-
* [Contributing](#contributing)
46-
* [License](#license)
47-
</details>
31+
- [Getting started](#getting-started)
32+
- [Installation](#installation)
33+
- [Inside your codebase](#inside-your-codebase)
34+
- [What does IntersectionObserver do?](#what-does-intersectionobserver-do)
35+
- [Why use this component?](#why-use-this-component)
36+
- [No bookkeeping](#no-bookkeeping)
37+
- [No extra markup](#no-extra-markup)
38+
- [Easy to adopt](#easy-to-adopt)
39+
- [Documentation](#documentation)
40+
- [Options](#options)
41+
- [Notes](#notes)
42+
- [Polyfill](#polyfill)
43+
- [IntersectionObserver's Browser Support](#intersectionobservers-browser-support)
44+
- [Contributing](#contributing)
45+
- [License](#license)
46+
</details>
4847

4948
---
5049

@@ -95,8 +94,7 @@ npm install --save intersection-observer
9594
> IntersectionObservers calculate how much of a target element overlaps (or "intersects with") the visible portion of a
9695
> page, also known as the browser's "viewport":
9796
>
98-
> [Dan Callahan](https://hacks.mozilla.org/2017/08/intersection-observer-comes-to-firefox/) · <a href="https://creativecommons.org/licenses/by-sa/3.0/">
99-
> <img id="licensebutton_slim" alt="Creative Commons License" src="https://i.creativecommons.org/l/by-sa/3.0/80x15.png" style="margin-right:10px;margin-bottom:4px; border: 0;"></a>
97+
> [Dan Callahan](https://hacks.mozilla.org/2017/08/intersection-observer-comes-to-firefox/)&nbsp;&middot;&nbsp;<a href="https://creativecommons.org/licenses/by-sa/3.0/"><img id="licensebutton_slim" alt="Creative Commons License" src="https://i.creativecommons.org/l/by-sa/3.0/80x15.png" style="margin-right:10px;margin-bottom:4px; border: 0;"></a>
10098
10199
![Graphic example](https://hacks.mozilla.org/files/2017/08/Blank-Diagram-Page-1.png)
102100

@@ -118,8 +116,8 @@ up and re-observes nodes on-demand to avoid any unexpected memory leaks.
118116
### No extra markup
119117

120118
ReactIntersectionObserver does not create any extra DOM elements, it attaches to the only child you'll provide to it.
121-
Internally it warns you if attaching a `ref` to it fails - common mistake when using a stateless component in React 15 -
122-
and will invoke any existing `ref` callback upon the passed child element.
119+
This is done using `findDOMNode` to retrieve the first DOM node found. If your child already has an existing `ref`,
120+
either a callback or object (from createRef), these will be handled normally in either case.
123121

124122
### Easy to adopt
125123

@@ -131,10 +129,10 @@ upon.
131129

132130
Some of the things you may want to use ReactIntersectionObserver for:
133131

134-
* Determining advertisement impressions
135-
* Lazy loading - Images, or anything that will enter the viewport
136-
* Occlusion culling - Don't render an object until is close to the viewport edges
137-
* [Sentinel Scrolling - Infinite scroller with a recycled Sentinel](https://github.com/researchgate/react-intersection-list)
132+
- Determining advertisement impressions
133+
- Lazy loading - Images, or anything that will enter the viewport
134+
- Occlusion culling - Don't render an object until is close to the viewport edges
135+
- [Sentinel Scrolling - Infinite scroller with a recycled Sentinel](https://github.com/researchgate/react-intersection-list)
138136

139137
## Documentation
140138

@@ -150,8 +148,7 @@ Find multiple examples and usage guidelines under:
150148
Recipes are useful code snippets solutions to common problems, for example, how to use ReactIntersectionObserver within
151149
a
152150
[Higher Order Component](https://researchgate.github.io/react-intersection-observer/?selectedKind=Recipes&selectedStory=Higher%20Order%20Component).
153-
<br>
154-
Here's how to create an **element monitoring** component:
151+
<br> Here's how to create an **element monitoring** component:
155152

156153
```jsx
157154
import React, { Component } from 'react';
@@ -162,28 +159,26 @@ export default class ViewableMonitor extends Component {
162159
static propTypes = {
163160
tag: PropTypes.node,
164161
children: PropTypes.func.isRequired,
165-
}
162+
};
166163

167164
static defaultProps = {
168165
tag: 'div',
169-
}
166+
};
170167

171168
state = {
172169
isIntersecting: false,
173-
}
170+
};
174171

175172
handleChange = ({ isIntersecting }) => {
176173
this.setState({ isIntersecting });
177174
};
178-
175+
179176
render() {
180177
const { tag: Tag, children, ...rest } = this.props;
181178

182179
return (
183180
<Observer {...rest} onChange={this.handleChange}>
184-
<Tag>
185-
{children(this.state.isIntersecting)}
186-
</Tag>
181+
<Tag>{children(this.state.isIntersecting)}</Tag>
187182
</Observer>
188183
);
189184
}
@@ -195,16 +190,28 @@ import React from 'react';
195190
import ViewableMonitor from './ViewableMonitor';
196191

197192
export default () => (
198-
<ViewableMonitor>
199-
{isViewable =>
200-
isViewable ? 'I am viewable' : 'I am still hiding'
201-
}
202-
</ViewableMonitor>
193+
<ViewableMonitor>{isViewable => (isViewable ? 'I am viewable' : 'I am still hiding')}</ViewableMonitor>
203194
);
204195
```
205196

206197
Discover more recipes in our [examples section](docs/README.md).
207198

199+
### Exception handling
200+
201+
By default, an `invariant` error is thrown if there isn't a DOM node to observe when mounted. We've added a helpful and descriptive message that's supposed to help you identify potential problems early on. However, this could also unexpectedtly trigger in production, specially with dynamic children, causing a bigger problem (bubbling up) if not handled correctly (e.g.: error boundary). In such cases, you can set the config for the error reporter to adjust it to your needs:
202+
203+
```js
204+
import { Config } from '@researchgate/react-intersection-observer';
205+
206+
Config.errorReporter(function(errorMsg) {
207+
if (process.env.NODE_ENV === 'production') {
208+
sendReport((errorMsg);
209+
} else {
210+
console.error(errorMsg);
211+
}
212+
});
213+
```
214+
208215
### Options
209216
210217
**root**: `HTMLElement|string` | default `window object`
@@ -230,21 +237,21 @@ disabling the observing mechanism and restoring it later.
230237
231238
Function that will be invoked whenever an observer's callback contains this target in its changes.
232239
233-
**children** (required): `React.Element<*>`
240+
**children**: `React.Element<*>|null`
234241
235-
Single React component or element that is used as the target (observable).
242+
Single React component or element that is used as the target (observable). As of `v1.0.0`, children can be null. Null children won't be observed.
236243
237244
### Notes
238245
239-
* According to the spec, an initial event is being fired when starting to observe a non-intersecting element as well.
240-
* _Edge's implementation seems to
241-
[miss the initial event](https://github.com/w3c/IntersectionObserver/issues/222#issuecomment-311539591), although
242-
Edge 16 behavior aligns with the spec._
243-
* Changes happen asynchronously, similar to the way `requestIdleCallback` works.
244-
* Although you can consider callbacks immediate - always below 1 second - you can also get an immediate response on an
245-
element's visibility with `observer.takeRecords()`.
246-
* The primitives `Map` an `Set` are required. You may need to include a polyfill for browsers lacking ES2015 support. If
247-
you're using babel, include `"babel-polyfill"` somewhere to your codebase.
246+
- According to the spec, an initial event is being fired when starting to observe a non-intersecting element as well.
247+
- _Edge's implementation seems to
248+
[miss the initial event](https://github.com/w3c/IntersectionObserver/issues/222#issuecomment-311539591), although
249+
Edge 16 behavior aligns with the spec._
250+
- Changes happen asynchronously, similar to the way `requestIdleCallback` works.
251+
- Although you can consider callbacks immediate - always below 1 second - you can also get an immediate response on an
252+
element's visibility with `observer.takeRecords()`.
253+
- The primitives `Map` an `Set` are required. You may need to include a polyfill for browsers lacking ES2015 support. If
254+
you're using babel, include `"babel-polyfill"` somewhere to your codebase.
248255
249256
## Polyfill
250257
@@ -313,10 +320,10 @@ onChange = entry => requestIdleCallback(() => this.handleChange(entry));
313320
</tr>
314321
</table>
315322
316-
* [1][reportedly available](https://www.chromestatus.com/features/5695342691483648), it didn't trigger the events on
317-
initial load and lacks `isIntersecting` until later versions.
318-
* [2] This feature was implemented in Gecko 53.0 (Firefox 53.0 / Thunderbird 53.0 / SeaMonkey 2.50) behind the
319-
preference `dom.IntersectionObserver.enabled`.
323+
- [1][reportedly available](https://www.chromestatus.com/features/5695342691483648), it didn't trigger the events on
324+
initial load and lacks `isIntersecting` until later versions.
325+
- [2] This feature was implemented in Gecko 53.0 (Firefox 53.0 / Thunderbird 53.0 / SeaMonkey 2.50) behind the
326+
preference `dom.IntersectionObserver.enabled`.
320327
321328
### Using polyfill
322329

docs/docs/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import 'babel-polyfill';
1+
import '@babel/polyfill';
22
import 'intersection-observer';
33
import React from 'react';
44
import { storiesOf } from '@storybook/react';

0 commit comments

Comments
 (0)