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

@Watch methods not firing in code build as dist-custom-elements-bundle output target #2478

Closed
TdroL opened this issue Jun 1, 2020 · 1 comment

Comments

@TdroL
Copy link

TdroL commented Jun 1, 2020

https://tdrol.github.io/stencil-custom-elements-watch-bug/

Stencil version:

 @stencil/core@1.14.0

I'm submitting a:

[x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://stencil-worldwide.herokuapp.com/ or https://forum.ionicframework.com/

Current behavior:

In code build as dist-custom-elements-bundle output, @Watch decorated methods are not executed when watched attribute is changed dynamically.

Expected behavior:

Methods decorated with @Watch should be executed on attribute change in code generated by as dist-custom-elements-bundle output.

Steps to reproduce:

  1. Clone repo TdroL/stencil-custom-elements-watch-bug
  2. Run npm install and npm run build
  3. Start a web server in dist/ folder and open dist/index.html
  4. Click either of "Change prop" buttons and observe watchCallCount=... values

Demo

Related code:

@Component({
  tag: 'my-component',
  shadow: true
})
export class MyComponent {
  @Prop() prop: string = '0';
  @State() watchCallCount = 0;

  @Watch('prop')
  updateProp() {
    this.watchCallCount++
  }

  render() {
    return <pre>prop={this.prop}; watchCallCount={this.watchCallCount}</pre>;
  }
}
<my-component prop="0"></my-component>

<button onclick="document.querySelector('my-component').setAttribute('prop', Date.now());">Change prop</button>

Other information:

Watchers are executed only if isWatchReady flag is set on the component (src/runtime/set-value.ts#L50), but this flag is set only when build target has either lazyLoad or hydrateClientSide set to true (src/runtime/initialize-component.ts#L29) and dist-custom-elements-bundle target has both of them set to false (src/compiler/output-targets/dist-custom-elements-bundle/custom-elements-build-conditionals.ts)

@ionitron-bot ionitron-bot bot added the triage label Jun 1, 2020
@simonhaenisch simonhaenisch added bug and removed triage labels Jun 3, 2020
@adamdbradley
Copy link
Contributor

Thank you for putting together a great repo case! We'll get this fixed up and in the next release

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

No branches or pull requests

3 participants