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

Using window.onresize and document.querySelector is unsafe #3

Closed
smalluban opened this issue May 4, 2020 · 2 comments
Closed

Using window.onresize and document.querySelector is unsafe #3

smalluban opened this issue May 4, 2020 · 2 comments
Assignees
Labels
enhancement New feature or request performance question Further information is requested standards
Milestone

Comments

@smalluban
Copy link

Question

It's not a bug, so I've chosen the "question" template. I looked at the source code, and I've found some worrying parts:

document.querySelector("instagram-widget").shadowRoot.querySelector(".instagram-widget-photos").innerHTML = html;

Your code won't work if there will be more elements on the same page. It will always update the first one. You can just reference your element by this - so instead querying document to access shadowRoot, you can use this.shadowRoot (after initializing it).

window.onresize = () => {

This is unsafe and can break other code. You assume that the user won't use window.onresize syntax, but he can, and then your callback is gone. You should use window.addEventListener().

if (self.options["force-square"] === "yes") {

Because of that, the onresize will only refer to the last instance of your component, so the above setting will apply from the last instance.

@ptkdev
Copy link
Member

ptkdev commented May 4, 2020

Nice feedback! Thanks!
This is my first component so it's not perfect. Pull request is welcome! It is not expected to fill a page with this component, it should be 1 per page so I didn't get this problem.

I will try to solve the problem with v2.5.0

@ptkdev ptkdev self-assigned this May 4, 2020
@ptkdev ptkdev added enhancement New feature or request performance question Further information is requested standards labels May 4, 2020
@ptkdev ptkdev added this to the v2.5.0 milestone May 4, 2020
@ptkdev
Copy link
Member

ptkdev commented May 4, 2020

@smalluban Thank's bro. I added you to README.md as a contributor. Fix available in v2.5.0

@ptkdev ptkdev closed this as completed May 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request performance question Further information is requested standards
Projects
None yet
Development

No branches or pull requests

2 participants