Skip to content

[Bug] Component are re-rendered even if not needed  #115

Closed
@titouancreach

Description

@titouancreach

Given 2 very simple child components

MyInput.jsx

export default {
  props: ['update', 'value'],
  
  render(h) {
    return (
      <div>
       <input value={this.value} onInput={this.update} />
      </div>
    );
  }
};

and
Foobar.jsx

export default {
  updated() {
    console.log('FOOBAR is updated');
  },

  render(h) {
    return (
      <div>
       FOOBAR
      </div>
    );
  }
};

And the wrapper component:

export default {
  data: () => ({
    value: 'myval'
  }),

  methods: {
    update(v) {
      this.value = v;
    }
  },
  
  render(h) {
    return (
      <div>
       <MyInput value={this.value} update={this.update} />
       <Foobar />
      </div>
    );
  }
};

Each time my value in the input is updated, then, the message: FOOBAR is updated is displayed.
It make no sence to re-render FooBar component that depends on no props.

Template version doesn't rerender Foobar:

<template>
  <div>
    <MyInput :update=update :value=value />
    <FooBar />
  </div>
</template>

FOOBAR is updated is not displayed.

The h version also work:

render(h) {
  return h('div', [
    h('FooBar'),
    h('MyInput', {props: {value: this.value, update: this.update}})
  ]);
};

That look very weird because I thought the JSX version compile into my h version. This bug makes all my child components to be rerender even if they don't need.

Update: I noticed that:

  h('Foobar', [])

Display the message whereas

  h('Foobar')

Work as expected.
I don't know why the behavior is different in this case, I'll also open an issue in Vue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions