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

Issue 414 #425

Merged
merged 5 commits into from
May 17, 2017
Merged

Issue 414 #425

merged 5 commits into from
May 17, 2017

Conversation

piotr-gawron
Copy link
Contributor

@piotr-gawron piotr-gawron commented Jun 29, 2016

This PR fixes issue #414. However, there are problems with tests now. Tests works perfectly fine when
they are run in a browser, but when test are run in a console there are errors. The errors can be summarized as: object 'document' has no function 'contains'.

Can you help me with tests?

Summary of my PR: when pileup is created with 'element' that doesn't belong to DOM, observer object is created. This observer observes document object. When 'element' is added to document (or to any (grand)child) of document pileup tracks are forced to rerender by changing updateSize state of ReactElements.

Sorry for the commits comments but I have problems with lint and git in general ;/


This change is Reviewable

//if the element doesn't belong to document DOM observe DOM to detect
//when it's attached
var observer = null;
if (!document.contains(el)) {
Copy link
Member

Choose a reason for hiding this comment

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

TIL that document.contains is not a standard thing: http://stackoverflow.com/questions/20557115/mocha-casperjs-headless-testing-document-contains-undefined

but if (!document.body.contains(el)) { works fine as suggested in that SO answer. This should fix the issue with the headless tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I dissagree with this answer at SO. Here you have better source:
https://developer.mozilla.org/en-US/docs/Web/API/Node/contains

It is a standard, the only remark is that IE doesn't support it for document but only for document.body.

I can change it to document.body if it solves the problem.

Anyway, I took it from this answer at SO:
http://stackoverflow.com/questions/5629684/how-to-check-if-element-exists-in-the-visible-dom/5629730#5629730

Copy link
Member

Choose a reason for hiding this comment

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

as an alternative, you can do:

var contains = document.contains || document.body.contains;
if (!contains(el)) {
...
}

PhantomJS framework can sometimes surface issues like this; but, the pros still outweigh its cons, so we are still sticking to it. Also, any such issue will affect people trying to render views in headless mode, so it would be great if we address this even though it is a weird workaround.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this doesn't work: I get some strange Invalid invocation error in Chrome, Firefox reports different error...

But I fixed it by replacing: document.contains with document.body.contains

@armish
Copy link
Member

armish commented Jun 30, 2016

thanks @piotr-gawron! See my inline comments/questions regarding some functionality and performance issues.

It would also be great to be able to replicate this issue within a unit test, but I do understand it might be tricky/unfeasible to do so. But having such as a case might help us do some benchmarking and performance monitoring.

On a side note: do you think it would be better if we expose an updateSize method within the main pileup object and document this edge case in case somebody else hits a similar issue? That way, we don't have to think about how this might affect other users in a broader sense.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.6%) to 91.081% when pulling 04d0da5 on piotr-gawron:issue-414 into ed543e6 on hammerlab:master.

@piotr-gawron
Copy link
Contributor Author

@armish
Sorry for long answer - it's vacations time and I wasn't available for the last 2 weeks.

…er tag that was dynamically added pileup component wasn't updated
@coveralls
Copy link

Coverage Status

Coverage decreased (-0.6%) to 91.071% when pulling 8480090 on piotr-gawron:issue-414 into ed543e6 on hammerlab:master.

@piotr-gawron
Copy link
Contributor Author

@armish I created this PR almost a year ago. Do you plan to merge it? Or there are some issues with my code?

@armish
Copy link
Member

armish commented May 17, 2017

hey @piotr-gawron - sorry that this fell through the cracks and I wasn't able to get back to you with my second round of reviews. I originally wanted to do some style/type cleaning up on your code before merging in, but for the last few months, I barely have the additional time to channel into pileup maintenance.

Let me just take a quick look at your PRs and I will merge them in if there are no apparent red flags.

Apologies for the delay.

@armish armish merged commit 189b18b into hammerlab:master May 17, 2017
@piotr-gawron piotr-gawron deleted the issue-414 branch May 2, 2019 12:28
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.

None yet

3 participants