0

Both with svelte-apollo (https://github.com/timhall/svelte-apollo/issues/19) and @urql-svelte (https://github.com/FormidableLabs/urql/issues/704) I'm having an entire list re-render instead of just an element re-render.

Reproduction steps:

If I read here: https://svelte.dev/tutorial/svelte-options, I understand that by using:

immutable={true} — you never use mutable data, so the compiler can do simple referential equality checks to determine if values have changed

immutable={false} — the default. Svelte will be more conservative about whether or not mutable objects have changed

If you see the example they are changing the todos array as we are also doing with urql:

let todos = [
  { id: 1, done: true, text: 'wash the car' },
  { id: 2, done: false, text: 'take the dog for a walk' },
  { id: 3, done: false, text: 'mow the lawn' }
];

function toggle(toggled) {
  todos = todos.map(todo => {
    if (todo === toggled) {
      // return a new object
      return {
        id: todo.id,
        text: todo.text,
        done: !todo.done
      };
    }

    // return the same object
    return todo;
  });
}

Why it doesn't work with my REPL todos example?

Is todos a new array at the end?

Community
  • 1
  • 1
Fred Hors
  • 3,258
  • 3
  • 25
  • 71
  • When you say "every button re-renders; so the entire list re-render itself", how did you ascertain that? – joshnuss Apr 17 '20 at 18:37
  • Did you see the "flash" effect on each buttons here: https://codesandbox.io/s/urql-svelte-list-rerendering-uwsvn? – Fred Hors Apr 17 '20 at 21:54
  • Yes, that's what I wanted to clarify. The flash is triggered by `afterUpdate`, that doesn't mean the component was re-added to DOM, that would trigger in `onMount`. – joshnuss Apr 17 '20 at 21:59
  • Ok. I think I have some confusion about "re-adding", "re-rendering" and "re-painting" and what else? – Fred Hors Apr 18 '20 at 00:06

0 Answers0