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

bug: Stencil compiler overrides initial prop value from html #3185

Closed
3 tasks done
theo-staizen opened this issue Dec 14, 2021 · 3 comments
Closed
3 tasks done

bug: Stencil compiler overrides initial prop value from html #3185

theo-staizen opened this issue Dec 14, 2021 · 3 comments
Labels
Bug: Validated This PR or Issue is verified to be a bug within Stencil Has Workaround This PR or Issue has a work around detailed within it.

Comments

@theo-staizen
Copy link

theo-staizen commented Dec 14, 2021

Prerequisites

Stencil Version

2.10.0

Current Behavior

Environment: Compiling In browser. Not sure if this is happening in Node too.

As of 2.10.0, I noticed that the compiler is introducing an instance prop to the generated class and that causes it to clobber/overwrite the initial value given by the html string.

For example, given <my-cmp name="theo"></my-cmp> name will be undefined instead of theo

Expected Behavior

Initial values from html should be preserved during construction, similar to 2.9.0

The compiler from 2.9.0 outputs

let CmpA = class extends HTMLElement {
  constructor() {
    super();
    this.__registerHost();
  }
  render() {
    return h("h1", null,
      "Hello ",
      this.name);
  }
};
__stencil_defineCustomElement(CmpA, [0, "cmp-a", {
    "name": [8]
  }]);

Steps to Reproduce

Given the following component

@Component({ tag: 'cmp-a' })
export class CmpA {
  @Prop() name
  render() {
    return <h1>Hello {this.name}</h1>
  }
}

The compiler outputs

let CmpA = class extends HTMLElement {
  constructor() {
    super();
    this.__registerHost();
  }
  name; // <<<<<< THIS IS NEW AS OF 2.10.0
  render() {
    return h("h1", null,
      "Hello ",
      this.name);
  }
};
__stencil_defineCustomElement(CmpA, [0, "cmp-a", {
    "name": [8]
  }]);

Code Reproduction URL

https://jsfiddle.net/n5oL4613/

Additional Information

Possibly duplicates/relates to #3130

@ionitron-bot ionitron-bot bot added the triage label Dec 14, 2021
@rwaskiewicz
Copy link
Contributor

I agree this probably relates to #3130, I'll see if I can take a closer look this afternoon after meetings or first thing in the AM

@rwaskiewicz
Copy link
Contributor

👋 I confirmed that this is indeed related to #3130 - when no target field is given as a part of the second argument to transpileSync, Stencil defaults to ESNext. It's in that compilation target that this issue (and the one in #3130) that this presents.

I'm going to label this to tie it to the existing issue in our internal tracking system. In the meantime, there's a workaround where the target key/value pair can be added to the second argument of transpileSync like so:

const { code } = window.stencil.transpileSync(
  src, 
  {
     sourceMap: false,
+    target: 'es2020', 
  }
);

@rwaskiewicz rwaskiewicz added Bug: Validated This PR or Issue is verified to be a bug within Stencil Feature: Compiler Has Workaround This PR or Issue has a work around detailed within it. and removed Bug: Needs Validation labels Dec 15, 2021
@theo-staizen
Copy link
Author

Excellent, thank you for the quick response and the workaround.
I'll close the issue to reduce the noise :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug: Validated This PR or Issue is verified to be a bug within Stencil Has Workaround This PR or Issue has a work around detailed within it.
Projects
None yet
Development

No branches or pull requests

2 participants