Skip to content

Commit

Permalink
Fix some code to work when propTypes are stripped in prod mode
Browse files Browse the repository at this point in the history
our babel configuration removes all of the PropType declarations
From our code in when build for production mode.
(See 'transform-react-remove-prop-types' in babel.config.js)
That is because react does not actually do any prop-type verifying
In prod mode so that code would be just wasted bytes sent to the browser

This means that our code should not actually depend on propTypes
at runtime

The way this was written, it was depending on 
CanvasAsyncSelect.propTypes existing even in prod mode

Test plan:
* if you run the code that uses this in prod mode you shouldn’t get
  react-dom.production.min.js:193 TypeError: Cannot read property 
  'renderLabel' of undefined

Change-Id: I598bbc25887b5fdd85a6ed77debf14020ea42376
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/218037
Tested-by: Service Cloud Jenkins <[email protected]>
Tested-by: Jenkins
Reviewed-by: Anju Reddy <[email protected]>
QA-Review: Anju Reddy <[email protected]>
Product-Review: Ryan Shaw <[email protected]>
  • Loading branch information
ryankshaw committed Nov 20, 2019
1 parent ecfa985 commit a73fc0b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/jsx/shared/components/ContentShareUserSearchSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ import {func, string} from 'prop-types'
import CanvasAsyncSelect from './CanvasAsyncSelect'
import useDebouncedSearchTerm from '../hooks/useDebouncedSearchTerm'
import useContentShareUserSearchApi from '../effects/useContentShareUserSearchApi'

import UserSearchSelectorItem from './UserSearchSelectorItem'

const {renderLabel, ...restOfSelectPropTypes} = CanvasAsyncSelect.propTypes

ContentShareUserSearchSelector.propTypes = {
courseId: string.isRequired,
onUserSelected: func, // (basicUser) => {} (see proptypes/user.js)
...restOfSelectPropTypes
...(() => {
const {renderLabel, ...restOfSelectPropTypes} = CanvasAsyncSelect.propTypes
return restOfSelectPropTypes
})()
}

const MINIMUM_SEARCH_LENGTH = 3
Expand Down

0 comments on commit a73fc0b

Please sign in to comment.