WebReflection / hyperHTML

A Fast & Light Virtual DOM Alternative
ISC License
3.07k stars 112 forks source link

onconnected called twice on IE < 11 #291

Closed lovetingyuan closed 5 years ago

lovetingyuan commented 5 years ago

import todoItem from '@/js/components/todo-item';
import todoInput from '@/js/components/todo-input';

export default class TodoList extends Component {
  get defaultState() {
    return { list: [] };
  }
  constructor(props) {
    super();
    this.props = props;
  }
  onconnected() {
    console.log('connected called twice!');
    listen({
      'todolist/add': text => {
        this.state.list.push({
          text: text,
          id: Math.random()
        });
        this.render();
      },
      'todolist/delete': id => {
        this.state.list = this.state.list.filter(item => item.id != id);
        this.render();
      }
    });
  }
  render() {
    const { list } = this.state;
    return this.html`
      <section class="todo-list">
        <p>
          todo list(${list.length}): ${todoInput()}
        </p>
        <ol onconnected=${this}>
          ${list.map(item => todoItem(item))}
          ${list.length ? '' : wire(this)`<i>no data</i>`}
        </ol>
      </section>
    `;
  }
}
lovetingyuan commented 5 years ago

Sorry, my fault, onconnected should be attached to root element.

WebReflection commented 5 years ago

Sorry, my fault, onconnected should be attached to root element.

@lovetingyuan to be honest, that shouldn't matter at all, and since yesterday I've released a version that should never see double notifications, I wonder if you can reproduce the error in there with latest.

lovetingyuan commented 5 years ago

I used v2.16.7, but still, onconnected will be called twice on IE < 11(IE11 works well). I guess it is caused by some browser compatibility problems. By the way, I used the umd version directly.

Thanks for your response!

WebReflection commented 5 years ago

It'd be awesome if you could verify v2.16.8 does not trigger twice on IE < 11, 'cause I've updated and counter-patched non MutationObserver capable browsers.

Thank You!

lovetingyuan commented 5 years ago

Awesome! I have tried v2.16.8, it works well. Now onconnected only be triggered once on IE 9 and 10. Thanks for your work!