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

Unnecessary props passed to DOM #95

Closed
breadadams opened this issue Mar 24, 2018 · 7 comments · Fixed by #169
Closed

Unnecessary props passed to DOM #95

breadadams opened this issue Mar 24, 2018 · 7 comments · Fixed by #169

Comments

@breadadams
Copy link
Member

image

Some props are leaking through to the DOM (unnecessarily) ☝️ (autoplay, controls, etc)

@Kikobeats
Copy link
Member

I know, but I consider the effort to remove it implies more cost than simply pass it

what do you think?

@breadadams
Copy link
Member Author

breadadams commented Mar 24, 2018

Yeah I had a quick go at it and gave up quickly 😅

I was thinking we could create a small util. method, where we pass props & the keys of props we want to exclude from a return object. Eg:

const propCleaner = (obj, excludeKeys) => {
  const objKeys = Object.keys(obj)

  return objKeys.reduce((acc, key) => {
    if (!excludeKeys.include(key)) {
      acc[key] = obj[key]
    }
    return acc
  })
}
 
<Component {...propCleaner(props, ['apiKey', 'autoPlay'])} />

(not ran/tested)

@Kikobeats
Copy link
Member

@breadadams
Copy link
Member Author

Yep that seems to do basically what I was suggesting.

We'll have to see how the size looks with it included - https://bundlephobia.com/result?p=clean-tag@1.0.4

@Kikobeats
Copy link
Member

I would not worry unless it represents a problem

The cost of add 11kb extra size into the library vs 0kb, also not logic for handle this 🙂

@breadadams
Copy link
Member Author

Just came across this @Kikobeats. Lodash's omit should do the trick.

I think we should implement this as we're generating slightly unsemantic markup, passing "media" attributes (autoplay, etc) to DOM elements that shouldn't receive them.

@Kikobeats
Copy link
Member

agree!

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 a pull request may close this issue.

2 participants