Skip to content

Commit ce9ca19

Browse files
authored
fix(perf): only compute snappoints when step is provided (#2699)
* chore: do not uglify in dev + better banner * fix(perf): only compute snappoints when step is provided This keeps the snapping as it snaps points to the rounded number if no snappoints are provided. Until rheostat provides a lazy way to fix the snappoints, there will also be a risk of having an "out of memory" error because the range of values is too big. There is an open issue opened for adding this new API: airbnb/rheostat#14 Fix #2662 * chore: fix lint * chore: fix lint
1 parent dd46cf4 commit ce9ca19

File tree

5 files changed

+32
-24
lines changed

5 files changed

+32
-24
lines changed

scripts/serve.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010
# folder through a local web server.
1111

1212
yarn
13-
NODE_ENV=production webpack-dev-server --config ./scripts/webpack.config.js --content-base dist/
13+
NODE_ENV=development webpack-dev-server --config ./scripts/webpack.config.js --content-base dist/

scripts/webpack.config.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ const UnminifiedWebpackPlugin = require('unminified-webpack-plugin');
1111
const extractCSS = new ExtractTextPlugin('instantsearch.css');
1212
const extractTheme = new ExtractTextPlugin('instantsearch-theme-algolia.css');
1313

14-
const { NODE_ENV = 'development', VERSION = 'UNRELEASED' } = process.env;
14+
const {
15+
NODE_ENV = 'development',
16+
VERSION = `UNRELEASED / generated at: ${new Date().toUTCString()}`,
17+
} = process.env;
18+
19+
const noop = () => ({ apply: () => undefined });
1520

1621
module.exports = {
1722
devtool: 'source-map',
@@ -76,24 +81,26 @@ module.exports = {
7681
new webpack.optimize.AggressiveMergingPlugin(),
7782
new webpack.optimize.ModuleConcatenationPlugin(),
7883

79-
new webpack.optimize.UglifyJsPlugin({
80-
compress: {
81-
warnings: false,
82-
comparisons: false,
83-
},
84-
output: {
85-
comments: false,
86-
ascii_only: true,
87-
},
88-
sourceMap: true,
89-
}),
84+
NODE_ENV === 'production'
85+
? new webpack.optimize.UglifyJsPlugin({
86+
compress: {
87+
warnings: false,
88+
comparisons: false,
89+
},
90+
output: {
91+
comments: false,
92+
ascii_only: true,
93+
},
94+
sourceMap: true,
95+
})
96+
: noop,
9097

9198
new webpack.BannerPlugin(
9299
`instantsearch.js ${VERSION} | © Algolia Inc. and other contributors; Licensed MIT | github.com/algolia/instantsearch.js`
93100
),
94101

95102
// Generate un-minified js along with UglifyJsPlugin
96-
new UnminifiedWebpackPlugin(),
103+
NODE_ENV === 'production' ? new UnminifiedWebpackPlugin() : noop,
97104

98105
new HappyPack({
99106
loaders: ['babel-loader'],

src/components/Slider/Slider.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export class RawSlider extends Component {
5555

5656
// creates an array of values where the slider should snap to
5757
computeSnapPoints({ min, max, step }) {
58+
if (!step) return undefined;
5859
return [...range(min, max, step), max];
5960
}
6061

src/widgets/range-slider/__tests__/__snapshots__/range-slider-test.js.snap

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ exports[`rangeSlider widget usage max option will use the results min when only
1616
pips={true}
1717
refine={[Function]}
1818
shouldAutoHideContainer={false}
19-
step={1}
19+
step={undefined}
2020
templateProps={
2121
Object {
2222
"templates": Object {
@@ -57,7 +57,7 @@ exports[`rangeSlider widget usage min option sets the right range 1`] = `
5757
pips={true}
5858
refine={[Function]}
5959
shouldAutoHideContainer={false}
60-
step={1}
60+
step={undefined}
6161
templateProps={
6262
Object {
6363
"templates": Object {
@@ -98,7 +98,7 @@ exports[`rangeSlider widget usage min option will use the results max when only
9898
pips={true}
9999
refine={[Function]}
100100
shouldAutoHideContainer={false}
101-
step={1}
101+
step={undefined}
102102
templateProps={
103103
Object {
104104
"templates": Object {
@@ -143,7 +143,7 @@ exports[`rangeSlider widget usage should \`collapse\` when options is provided 1
143143
pips={true}
144144
refine={[Function]}
145145
shouldAutoHideContainer={true}
146-
step={1}
146+
step={undefined}
147147
templateProps={
148148
Object {
149149
"templates": Object {
@@ -184,7 +184,7 @@ exports[`rangeSlider widget usage should \`shouldAutoHideContainer\` when range
184184
pips={true}
185185
refine={[Function]}
186186
shouldAutoHideContainer={true}
187-
step={1}
187+
step={undefined}
188188
templateProps={
189189
Object {
190190
"templates": Object {
@@ -225,7 +225,7 @@ exports[`rangeSlider widget usage should render without results 1`] = `
225225
pips={true}
226226
refine={[Function]}
227227
shouldAutoHideContainer={true}
228-
step={1}
228+
step={undefined}
229229
templateProps={
230230
Object {
231231
"templates": Object {
@@ -266,7 +266,7 @@ exports[`rangeSlider widget usage with results calls twice ReactDOM.render 1`] =
266266
pips={true}
267267
refine={[Function]}
268268
shouldAutoHideContainer={false}
269-
step={1}
269+
step={undefined}
270270
templateProps={
271271
Object {
272272
"templates": Object {
@@ -307,7 +307,7 @@ exports[`rangeSlider widget usage with results calls twice ReactDOM.render 2`] =
307307
pips={true}
308308
refine={[Function]}
309309
shouldAutoHideContainer={false}
310-
step={1}
310+
step={undefined}
311311
templateProps={
312312
Object {
313313
"templates": Object {

src/widgets/range-slider/range-slider.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ rangeSlider({
125125
* @property {boolean} [autoHideContainer=true] Hide the container when no refinements available.
126126
* @property {RangeSliderCssClasses} [cssClasses] CSS classes to add to the wrapping elements.
127127
* @property {boolean} [pips=true] Show slider pips.
128-
* @property {number} [step=1] Every handle move will jump that number of steps.
129128
* @property {number} [precision = 0] Number of digits after decimal point to use.
130129
* @property {boolean|RangeSliderCollapsibleOptions} [collapsible=false] Hide the widget body and footer when clicking on header.
130+
* @property {number} [step] Every handle move will jump that number of steps.
131131
* @property {number} [min] Minimal slider value, default to automatically computed from the result set.
132132
* @property {number} [max] Maximal slider value, defaults to automatically computed from the result set.
133133
*/
@@ -171,7 +171,7 @@ export default function rangeSlider(
171171
max,
172172
templates = defaultTemplates,
173173
cssClasses: userCssClasses = {},
174-
step = 1,
174+
step,
175175
pips = true,
176176
precision = 0,
177177
tooltips = true,

0 commit comments

Comments
 (0)