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

dom class value lost in a special case #181

Closed
ouzhenkun opened this issue Jun 7, 2016 · 4 comments
Closed

dom class value lost in a special case #181

ouzhenkun opened this issue Jun 7, 2016 · 4 comments

Comments

@ouzhenkun
Copy link
Contributor

ouzhenkun commented Jun 7, 2016

hi~ @developit

in this codepen:
http://codepen.io/ryan_ou/pen/rLOaJa?editors=0010 (5.0.0-beta9)

follow these steps you will see the issue:

  1. click Set background button
  2. click Hide/Show button 4 times
  3. in chrome dev tools - Elements tab you will see:
<div id="panel" class>
  <button>SetBackground true</button>
</div>

it should be:

<div id="panel" class='bg'>
  <button>SetBackground true</button>
</div>

If you change the vnode(id='panel') to be:

<div id='panel' className={hasBg ? 'bg' : 'a_not_exists_class'}>...</div>

the class will be correct.

It seems like that:
If a component.className has been set to null/undefined/'';
a dom's class will lost when preact re-use the component.base

@developit
Copy link
Member

Good catch. I believe this line is the suspect:
https://github.com/developit/preact/blob/master/src/vdom/diff.js#L248

@developit
Copy link
Member

Ahh - @zhenkunou looks like this is specific to className - the bug doesn't seem to occur when using class.

@developit
Copy link
Member

Fix released in 5.0.0-beta10.

@ouzhenkun
Copy link
Contributor Author

ouzhenkun commented Jun 7, 2016

I've updated the demo(5.0.0-beta10), it work now!! Great, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants