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

Avoid duplicated style declarations for detectElementResize #507

Merged
merged 1 commit into from
Dec 13, 2016

Conversation

edulan
Copy link
Contributor

@edulan edulan commented Dec 13, 2016

Issue

When using multiple instances of AutoSizer (or mounting and unmounting multiple times) a new style tag is being added to the document head. This is due to detectElementResize vendor library that forces creation every time it's called.

Approaches

Solution 1

Move stylesCreated variable outside of function scope. This way this variable would be set just once independently of how many times function is called.

Solution 2

Identify style tag with an id attribute so we don't duplicate it if it already exists.

Solution 3

Extract style declaration to RV styles.css file.

Current approach

I've opted for using an id as it ensures style tag is created even if it has been previously removed somehow.

Screenshot

Here you can see it in action:

detectElementResize

@bvaughn
Copy link
Owner

bvaughn commented Dec 13, 2016

Fantastic pull request. So much detail. 😁 Thanks!

@bvaughn bvaughn merged commit 03d9cc3 into bvaughn:master Dec 13, 2016
@edulan
Copy link
Contributor Author

edulan commented Dec 13, 2016

You are very welcome :)

@bvaughn
Copy link
Owner

bvaughn commented Dec 14, 2016

FYI this optimization has been published as version 8.8.0

@edulan
Copy link
Contributor Author

edulan commented Dec 14, 2016

Awesome @bvaughn 👏 👏

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.

2 participants