Skip to content

Commit 51f26fe

Browse files
committed
feat: make the component more ergonomic
- Progress is only reset to 0 when necessary - Fix a bug where the before interactive timer wasn't correctly cleared - Fix a bug where the setState throttler wouldn't be correctly cleared when changing progressInterval - maxProgressBeforeInteractive now only applies when resuming from SSR - Improve tests and demo BREAKING CHANGE: while the API hasn't changed, the internal behavior changed enough to worth having a major bump
1 parent 48d8fc2 commit 51f26fe

File tree

9 files changed

+1753
-257
lines changed

9 files changed

+1753
-257
lines changed

.stylelintrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "@moxy/stylelint-config",
3+
"ignoreFiles": [
4+
"!**/*.css"
5+
]
6+
}

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,17 @@ The `progressDecay` function signature is `(time) => <progress>`, where `time` i
146146
Type: `number`
147147
Default: 100
148148

149-
The interval, in ms, to report progress. The value of `progressInterval` will effectively throttle all the internal behavior of `<WaitForReact>`, including the frequency in which the `children` render prop will be called.
149+
The interval, in ms, in which progress will be incremented.
150150

151-
ℹ️ If you are using CSS transitions, the transition durations should be slightly smaller than `progressInterval`. This circumvents an issue with several browsers, such as Chrome and Firefox, where updating a CSS property in the middle of a transition will cause the animation to "restart".
151+
ℹ️ If you are using CSS transitions, the value of `progressInterval` should be slightly higher than the CSS transition duration. This circumvents an issue with several browsers, such as Chrome and Firefox, where updating a CSS property in the middle of a transition will cause the animation to "restart".
152152

153153
### promise
154154

155155
Type: `Promise` or `PProgress `
156156

157157
A promise to wait for, after the app becomes interactive.
158158

159-
When a standard `Promise` is given, `<WaitForReact>` will initiate a "fake progress" until the promise settles. However, you may pass a [`PProgress `](https://github.com/sindresorhus/p-progress). In this case, the progress reported by the promise will be used instead of the "fake progress".
159+
When a standard `Promise` is given, `<WaitForReact>` will initiate the same "fake progress" mentioned in [`progressDecay`](#progressdecay) until the promise settles. However, you may pass a [`PProgress `](https://github.com/sindresorhus/p-progress). In this case, the progress reported by the promise will be used instead of the "fake progress".
160160

161161
### children
162162

demo/pages/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import classNames from 'classnames';
33
import WaitForReact from '@moxy/react-wait-for-react';
44
import styles from './index.module.css';
55

6+
const transitionDuration = 200 + 50; // Keep this value slightly higher than the CSS counterpart
67
const applyProgressBeforeInteractive = `function (elements, progress) {
78
elements.progressBar.style = 'transform:scaleX(' + progress + ')';
89
}`;
@@ -14,7 +15,7 @@ const Home = () => (
1415
<WaitForReact
1516
applyProgressBeforeInteractive={ applyProgressBeforeInteractive }
1617
promise={ promise }
17-
progressInterval={ 200 }>
18+
progressInterval={ transitionDuration }>
1819
{ ({ progress }) => (
1920
<div className={ classNames(styles.splashScreen, { [styles.loaded]: progress >= 1 }) }>
2021
<div

demo/pages/index.module.css

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
/* stylelint-disable declaration-property-value-blacklist, unit-blacklist, scale-unlimited/declaration-strict-value */
2+
13
.splashScreen {
4+
--transition-duration: 200ms;
5+
26
position: fixed;
37
top: 0;
48
right: 0;
@@ -8,10 +12,11 @@
812
justify-content: center;
913
align-items: center;
1014
background-color: #131313;
11-
transition: opacity 0.4s 0.2s ease, visibility 0s 0.6s;
15+
transition: opacity 0.4s var(--transition-duration) ease, visibility 0s calc(0.4s + var(--transition-duration));
1216
}
1317

1418
.splashScreen.loaded {
19+
visibility: hidden;
1520
opacity: 0;
1621
}
1722

@@ -21,15 +26,16 @@
2126
right: 0;
2227
left: 0;
2328
height: 4px;
29+
transform: scaleX(0);
2430
transform-origin: left center;
2531
background: #fffd8f;
2632
pointer-events: none;
27-
transition: transform 0.2s linear;
33+
transition: transform var(--transition-duration) linear;
2834
}
2935

3036
.content {
3137
color: #fff;
38+
font-family: -apple-system, "Helvetica Neue", sans-serif;
3239
font-size: 34px;
33-
font-family: -apple-system, 'Helvetica Neue', sans-serif;
3440
font-weight: 300;
3541
}

0 commit comments

Comments
 (0)