-
Notifications
You must be signed in to change notification settings - Fork 934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix access error on document for react native #451
fix access error on document for react native #451
Conversation
The underlying issue is this line: https://github.com/paypal/downshift/blob/master/src/downshift.js#L95, and then the fact that, from there, there aren't checks to see if the environment is just an empty object or not. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Could you fixup a few things before we review the rest?
src/downshift.js
Outdated
@@ -658,12 +663,10 @@ class Downshift extends Component { | |||
this.inputId = firstDefined(this.inputId, rest.id, `${this.id}-input`) | |||
let onChangeKey | |||
/* istanbul ignore next (preact) */ | |||
if (preval`module.exports = process.env.BUILD_PREACT === 'true'`) { | |||
if (this.props.isPreact) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sorry, but doing this will prevent these statements from being eliminated during uglification resulting in a bigger bundle. Please restore all of these to what they were before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
README.md
Outdated
@@ -59,52 +59,52 @@ harder to contribute to. | |||
|
|||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> | |||
|
|||
* [Installation](#installation) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think your editor may have messed this stuff up. If you could run npx kcd-scripts format
before you commit that will ensure that everything's formatted properly. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It most assuredly did 😬
93c580e
to
d1f2ecb
Compare
addressed, I think |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me! Thanks :)
Ok, yeah, so I'm not sure what the preval is not defined issue is all about in the build. Are you getting that locally? Try running As for code coverage, we probably should set up some way to test the native build, but unfortunately that would take a fair amount of work. So if you can't cover some code due to react native, then add some well-placed |
872b711
to
1f58f8f
Compare
@kentcdodds passing tests now! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one thing. Everything else looks swell 👍
@@ -9,9 +9,7 @@ exports[`renders with React Native components 1`] = ` | |||
aria-expanded={false} | |||
autoComplete="off" | |||
id="downshift-0-input" | |||
onBlur={[Function]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm... It feels like this would be a regression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this snapshot (the react native snapshot) reflect that the code in the react native build doesn't handle those props / that they won't be there? I could pass through noops but I don't think that'd be right.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but before your changes, the input had these event handlers for react-native and after your chances it doesn't. That's the regression I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. We should ensure that the onBlur handler is still passed here.
src/downshift.js
Outdated
} else if ( | ||
preval`module.exports = process.env.BUILD_REACT_NATIVE === 'true'` | ||
) { | ||
onChangeKey = 'onChangeText' | ||
eventHandlers = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the rationale behind removing onBlur
from the event handlers that we use with React Native?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mistake on my part
@@ -9,9 +9,7 @@ exports[`renders with React Native components 1`] = ` | |||
aria-expanded={false} | |||
autoComplete="off" | |||
id="downshift-0-input" | |||
onBlur={[Function]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. We should ensure that the onBlur handler is still passed here.
onChangeText={[Function]} | ||
onKeyDown={[Function]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with removing this one, as onKeyDown
is unhandled on React Native.
Thanks for the review @eliperkins I think I forgot about this PR - I'll make the changes tonight. Apologies! |
- remove error throwing focus call in react native - remove unnessary event handler
1f58f8f
to
7bc8022
Compare
Hey @eliperkins and @kentcdodds - I've updated this PR to work with the master - it's ready to review again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! This ended up being a fairly trivial amount of code changed! 👏
Thank you so much! |
Hmmmmm... It appears that the react native snapshots are failing. Care to give this a look? https://travis-ci.org/paypal/downshift/builds/424888379 We can't release this until the build is working. |
Hey @kentcdodds I've updated the snapshot - |
🎉 This PR is included in version 2.2.2 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
) <!-- Thanks for your interest in the project. Bugs filed and PRs submitted are appreciated! Please make sure that you are familiar with and follow the Code of Conduct for this project (found in the CODE_OF_CONDUCT.md file). Also, please make sure you're familiar with and follow the instructions in the contributing guidelines (found in the CONTRIBUTING.md file). If you're new to contributing to open source projects, you might find this free video course helpful: http://kcd.im/pull-request Please fill out the information below to expedite the review and (hopefully) merge of your pull request! --> <!-- What changes are being made? (What feature/bug is being fixed here?) --> **What**: Solution for this issue: downshift-js#334 Handles the other cases where `document` is undefined <!-- Why are these changes necessary? --> **Why**: Error getting thrown for React Native due to `document` being undefined I think I could use some help in thinking of the best way to write a test for this. <!-- Have you done all of these things? --> **Checklist**: <!-- add "N/A" to the end of each line that's irrelevant to your changes --> <!-- to check an item, place an "x" in the box like so: "- [x] Documentation" --> * [x] Tests * [x] Ready to be merged <!-- In your opinion, is this ready to be merged as soon as it's reviewed? --> * [x] Added myself to contributors table <!-- this is optional, see the contributing guidelines for instructions --> <!-- feel free to add additional comments -->
What:
Solution for this issue: #334
Handles the other cases where
document
is undefinedWhy:
Error getting thrown for React Native due to
document
being undefinedI think I could use some help in thinking of the best way to write a test for this.
Checklist: