Skip to content

Commit

Permalink
fix: Revert "perf: improve code in hooks (#1213)"
Browse files Browse the repository at this point in the history
This reverts commit a3103d7.
  • Loading branch information
silviuaavram authored Jan 11, 2021
1 parent 2e25604 commit b387f61
Show file tree
Hide file tree
Showing 25 changed files with 730 additions and 440 deletions.
28 changes: 14 additions & 14 deletions .size-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
{
"downshift.cjs.js": {
"bundled": 146405,
"minified": 66980,
"gzipped": 14158
},
"downshift.umd.min.js": {
"bundled": 155757,
"minified": 51452,
"gzipped": 13855
"bundled": 151457,
"minified": 50039,
"gzipped": 13404
},
"downshift.umd.js": {
"bundled": 200156,
"minified": 69500,
"gzipped": 18257
"bundled": 201322,
"minified": 70558,
"gzipped": 18310
},
"downshift.esm.js": {
"bundled": 141675,
"minified": 62938,
"gzipped": 13923,
"bundled": 144191,
"minified": 65056,
"gzipped": 14198,
"treeshaked": {
"rollup": {
"code": 2275,
Expand All @@ -27,5 +22,10 @@
"code": 4626
}
}
},
"downshift.cjs.js": {
"bundled": 148914,
"minified": 69091,
"gzipped": 14413
}
}
34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"author": "Kent C. Dodds <[email protected]> (http://kentcdodds.com/)",
"license": "MIT",
"peerDependencies": {
"react": ">=16.12.0"
"react": ">=16.8.0"
},
"dependencies": {
"@babel/runtime": "^7.12.5",
Expand All @@ -74,39 +74,39 @@
"devDependencies": {
"@babel/helpers": "^7.12.5",
"@rollup/plugin-commonjs": "^17.0.0",
"@testing-library/cypress": "^7.0.3",
"@testing-library/dom": "^7.29.2",
"@testing-library/jest-dom": "^5.11.8",
"@testing-library/cypress": "^7.0.2",
"@testing-library/dom": "^7.28.1",
"@testing-library/jest-dom": "^5.11.6",
"@testing-library/preact": "^2.0.1",
"@testing-library/react": "^11.2.3",
"@testing-library/react-hooks": "^4.0.0",
"@testing-library/user-event": "^12.6.0",
"@types/jest": "^26.0.20",
"@testing-library/react": "^11.2.2",
"@testing-library/react-hooks": "^3.4.2",
"@testing-library/user-event": "^12.3.0",
"@types/jest": "^26.0.15",
"@types/react": "^17.0.0",
"babel-plugin-macros": "^3.0.1",
"babel-plugin-macros": "^3.0.0",
"babel-plugin-no-side-effect-class-properties": "0.0.7",
"babel-preset-react-native": "^4.0.1",
"buble": "^0.20.0",
"cpy-cli": "^3.1.1",
"cross-env": "^7.0.3",
"cypress": "^6.2.1",
"cross-env": "^7.0.2",
"cypress": "^6.0.1",
"docz": "^2.3.1",
"docz-theme-default": "^1.2.0",
"eslint-plugin-cypress": "^2.11.2",
"eslint-plugin-react": "7.22.0",
"flow-bin": "^0.142.0",
"eslint-plugin-react": "7.21.5",
"flow-bin": "^0.138.0",
"flow-coverage-report": "^0.8.0",
"kcd-scripts": "^7.5.3",
"kcd-scripts": "^7.3.0",
"npm-run-all": "^4.1.5",
"preact": "^10.5.9",
"preact": "^10.5.7",
"react": "^16.13.1",
"react-dom": "^17.0.1",
"react-native": "^0.63.4",
"react-test-renderer": "^17.0.1",
"rollup-plugin-babel": "^4.4.0",
"serve": "^11.3.2",
"start-server-and-test": "^1.11.7",
"typescript": "^4.1.3"
"start-server-and-test": "^1.11.6",
"typescript": "^4.1.2"
},
"eslintConfig": {
"extends": "./node_modules/kcd-scripts/eslint.js",
Expand Down
75 changes: 0 additions & 75 deletions src/hooks/reducer.js

This file was deleted.

25 changes: 0 additions & 25 deletions src/hooks/stateChangeTypes.js

This file was deleted.

35 changes: 35 additions & 0 deletions src/hooks/useCombobox/__tests__/getComboboxProps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,23 @@ describe('getComboboxProps', () => {
expect(console.error).not.toHaveBeenCalled()
})

test('will not be displayed if getComboboxProps is not called but environment is production', () => {
const originalEnv = process.env.NODE_ENV
process.env.NODE_ENV = 'production'
renderHook(() => {
const {getInputProps, getMenuProps} = useCombobox({
items,
})

getInputProps({}, {suppressRefError: true})
getMenuProps({}, {suppressRefError: true})
})

// eslint-disable-next-line no-console
expect(console.error).not.toHaveBeenCalled()
process.env.NODE_ENV = originalEnv
})

test('will not be displayed if called with a correct ref', () => {
const refFn = jest.fn()
const comboboxNode = {}
Expand All @@ -160,5 +177,23 @@ describe('getComboboxProps', () => {
// eslint-disable-next-line no-console
expect(console.error).not.toHaveBeenCalled()
})

test('will not be displayed if element ref is not set but environment is production', () => {
const originalEnv = process.env.NODE_ENV
process.env.NODE_ENV = 'production'
renderHook(() => {
const {getInputProps, getMenuProps, getComboboxProps} = useCombobox({
items,
})

getInputProps({}, {suppressRefError: true})
getMenuProps({}, {suppressRefError: true})
getComboboxProps()
})

// eslint-disable-next-line no-console
expect(console.error).not.toHaveBeenCalled()
process.env.NODE_ENV = originalEnv
})
})
})
35 changes: 35 additions & 0 deletions src/hooks/useCombobox/__tests__/getInputProps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1017,5 +1017,40 @@ describe('getInputProps', () => {
// eslint-disable-next-line no-console
expect(console.error).not.toHaveBeenCalled()
})

test('will not be displayed if getInputProps is not called but environment is production', () => {
const originalEnv = process.env.NODE_ENV
process.env.NODE_ENV = 'production'
renderHook(() => {
const {getMenuProps, getComboboxProps} = useCombobox({
items,
})

getMenuProps({}, {suppressRefError: true})
getComboboxProps({}, {suppressRefError: true})
})

// eslint-disable-next-line no-console
expect(console.error).not.toHaveBeenCalled()
process.env.NODE_ENV = originalEnv
})

test('will not be displayed if element ref is not set but environment is production', () => {
const originalEnv = process.env.NODE_ENV
process.env.NODE_ENV = 'production'
renderHook(() => {
const {getInputProps, getMenuProps, getComboboxProps} = useCombobox({
items,
})

getComboboxProps({}, {suppressRefError: true})
getMenuProps({}, {suppressRefError: true})
getInputProps()
})

// eslint-disable-next-line no-console
expect(console.error).not.toHaveBeenCalled()
process.env.NODE_ENV = originalEnv
})
})
})
35 changes: 35 additions & 0 deletions src/hooks/useCombobox/__tests__/getMenuProps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,5 +189,40 @@ describe('getMenuProps', () => {
// eslint-disable-next-line no-console
expect(console.error).not.toHaveBeenCalled()
})

test('will not be displayed if getMenuProps is not called but environment is production', () => {
const originalEnv = process.env.NODE_ENV
process.env.NODE_ENV = 'production'
renderHook(() => {
const {getInputProps, getComboboxProps} = useCombobox({
items,
})

getInputProps({}, {suppressRefError: true})
getComboboxProps({}, {suppressRefError: true})
})

// eslint-disable-next-line no-console
expect(console.error).not.toHaveBeenCalled()
process.env.NODE_ENV = originalEnv
})

test('will not be displayed if element ref is not set but environment is production', () => {
const originalEnv = process.env.NODE_ENV
process.env.NODE_ENV = 'production'
renderHook(() => {
const {getInputProps, getMenuProps, getComboboxProps} = useCombobox({
items,
})

getInputProps({}, {suppressRefError: true})
getMenuProps({}, {suppressRefError: true})
getComboboxProps()
})

// eslint-disable-next-line no-console
expect(console.error).not.toHaveBeenCalled()
process.env.NODE_ENV = originalEnv
})
})
})
28 changes: 27 additions & 1 deletion src/hooks/useCombobox/__tests__/props.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('props', () => {
renderHook(() => useCombobox())

expect(global.console.error.mock.calls[0][0]).toMatchInlineSnapshot(
`"Warning: Failed prop type: The prop \`items\` is marked as required in \`useCombobox\`, but its value is \`undefined\`."`,
`"Warning: Failed items type: The items \`items\` is marked as required in \`useCombobox\`, but its value is \`undefined\`."`,
)
})

Expand Down Expand Up @@ -1454,4 +1454,30 @@ describe('props', () => {
`"downshift: A component has changed the controlled prop \\"inputValue\\" to be uncontrolled. This prop should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled Downshift element for the lifetime of the component. More info: https://github.com/downshift-js/downshift#control-props"`,
)
})

test('should not throw the controlled error if on production', () => {
const originalEnv = process.env.NODE_ENV
process.env.NODE_ENV = 'production'

const {rerender} = renderCombobox({inputValue: 'controlled value'})

rerender({})

/* eslint-disable no-console */
expect(console.error).not.toHaveBeenCalled()
process.env.NODE_ENV = originalEnv
})

test('should not throw the uncontrolled error if on production', () => {
const originalEnv = process.env.NODE_ENV
process.env.NODE_ENV = 'production'

const {rerender} = renderCombobox()

rerender({inputValue: 'controlled value'})

/* eslint-disable no-console */
expect(console.error).not.toHaveBeenCalled()
process.env.NODE_ENV = originalEnv
})
})
Loading

0 comments on commit b387f61

Please sign in to comment.