Skip to content
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

Merged
merged 2 commits into from
Sep 5, 2018

Conversation

samuelfullerthomas
Copy link
Contributor

@samuelfullerthomas samuelfullerthomas commented Jun 1, 2018

What:
Solution for this issue: #334
Handles the other cases where document is undefined

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.

Checklist:

  • Tests
  • Ready to be merged
  • Added myself to contributors table

@samuelfullerthomas
Copy link
Contributor Author

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.

Copy link
Member

@kentcdodds kentcdodds left a 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) {
Copy link
Member

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.

Copy link
Contributor Author

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)
Copy link
Member

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!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It most assuredly did 😬

@samuelfullerthomas samuelfullerthomas force-pushed the check-for-rn branch 2 times, most recently from 93c580e to d1f2ecb Compare June 1, 2018 16:15
@samuelfullerthomas
Copy link
Contributor Author

addressed, I think

kentcdodds
kentcdodds previously approved these changes Jun 1, 2018
Copy link
Member

@kentcdodds kentcdodds left a 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 :)

@kentcdodds
Copy link
Member

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 npm run validate to see.

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 /* istanbul ignore next */ comments. You can see the coverage report by opening coverage/lcov-report/index.html in your browser. Good luck!

@samuelfullerthomas
Copy link
Contributor Author

@kentcdodds passing tests now!

Copy link
Member

@kentcdodds kentcdodds left a 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]}
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor

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 = {
Copy link
Contributor

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?

Copy link
Contributor Author

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]}
Copy link
Contributor

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]}
Copy link
Contributor

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.

@samuelfullerthomas
Copy link
Contributor Author

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
@samuelfullerthomas
Copy link
Contributor Author

Hey @eliperkins and @kentcdodds - I've updated this PR to work with the master - it's ready to review again.

Copy link
Contributor

@eliperkins eliperkins left a 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! 👏

@kentcdodds kentcdodds merged commit d8d5722 into downshift-js:master Sep 5, 2018
@kentcdodds
Copy link
Member

Thank you so much!

@kentcdodds
Copy link
Member

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.

@samuelfullerthomas
Copy link
Contributor Author

Hey @kentcdodds I've updated the snapshot - npm run test:build works for me locally now

@kentcdodds
Copy link
Member

🎉 This PR is included in version 2.2.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Rendez pushed a commit to Rendez/downshift that referenced this pull request Sep 30, 2018
)


<!--
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 -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants