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

Force a node to be replaced, and not patched #1189

juanmiguelbesada opened this Issue Oct 30, 2018 · 1 comment


None yet
2 participants

juanmiguelbesada commented Oct 30, 2018

Stencil version:


I'm submitting a:

[] bug report
[x] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: or

Current behavior:

There is no way to force stencil to replace a child node. At this moment, when you update a state, it triggers render, but it patch the vnodes but not replace is. This cause that if one vnode has some type of initialization (in my use case is a amp-img element) it do not trigger the initialization again when update.

Expected behavior:
Allow somehow to force the vnodes to be replaced instead of patched. Or just replace the whole component

Steps to reproduce:

Related code:

import { Component, State, Method } from '@stencil/core';
import { Todo } from '../../declarations/Todo';

  tag: 'todo-list'
export class TodoList {
  cont: number = 2;
  @State() todos: Todo[] = [
    {id: "1", value: 1},
    {id: "2", value: 2},

  addTodo() {
    this.todos = [...this.todos, {id: this.cont.toString(), value: this.cont}];

  editTodo() {
    this.todos[1] = {...this.todos[1], value: this.todos[1].value + 1};

  render() {
    return (
      <div class="todo-list">
        { => (<todo-item todo={todo}></todo-item>))}
        <button type="button" onClick={() => this.addTodo()}>Add todo</button>
        <button type="button" onClick={() => this.editTodo()}>Edit todo</button>
import { Component, Prop, ComponentDidLoad, ComponentWillUpdate, ComponentDidUpdate, ComponentWillLoad, Watch } from '@stencil/core';
import { Todo } from '../../declarations/Todo';

  tag: 'todo-item'
export class TodoItem implements ComponentWillLoad, ComponentDidLoad, ComponentWillUpdate, ComponentDidUpdate {
    @Prop() todo: Todo;

    fooEl!: HTMLElement;

    componentWillLoad() {

    componentDidLoad() {
        //Do some component initialization = this.todo.value + 'px';

    componentWillUpdate() {


    render() {
        return (
            <div class="todo-item">
                <div style={{border: "1px solid red"}} ref={(el) => this.fooEl = el}>{} - {this.todo.value}</div>

Other information:
At TodoItem.componentDidLoad we just set the borderWith to the todoValue. (This is just to simulate what amp-img do). We have no way to replace the fooEl. If i remove the note in the componentWillUpdate event, the render will not create a new node.

@ionitron-bot ionitron-bot bot added the triage label Oct 30, 2018


This comment has been minimized.


adamdbradley commented Oct 31, 2018

Thank you for your feedback, but recreating the same node within the patch function is not a feature we'll be adding to Stencil. Thanks

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