ionic-team / stencil-ds-output-targets

These are output targets that can be added to Stencil for React and Angular.
https://stenciljs.com
MIT License
251 stars 117 forks source link

bug: methods non decorated are available on React component #417

Open dpellier opened 9 months ago

dpellier commented 9 months ago

Prerequisites

Stencil Version

4.12

Stencil Framework Output Target

React

Stencil Framework Output Target Version

0.5.3

Current Behavior

As described in the Stencil documentation: The @Method() decorator is used to expose methods on the public API. This works as expected for vanilla component, but the React output ones can access any methods regarding of the presence of the decorator.

Expected Behavior

Non decorated methods should not be accessible from the React component.

Steps to Reproduce

Given a simple component:

@Component({
  shadow: true,
  tag: 'my-text',
})
export class MyText {
  @Prop({ reflect: true }) text?: string;

  @Method()
  async publicFormatText(text?: string): Promise<string> {
    return text || 'nothing'
  }

  private privateFormatText(text?: string): string {
    return text || 'nothing'
  }

  render(): JSX.Element {
    return (
      <Host>
        <p>{ this.formatText(this.text) }</p>
      </Host>
    );
  }
}

When using as vanilla component:

document.querySelector('my-text').publicFormatText(....) // => call the method => OK
document.querySelector('my-text').privateFormatText(....) // => function does not exists => OK

But as React ref:

// using ref
const textRef = useRef(null);

// render
<OdsText ref={ textRef }
               text="Welcome" />

// calls
textRef.current?.publicFormatText() // => call the method => OK
textRef.current?.privateFormatText() // => call the method => KO => this should not be possible

Code Reproduction URL

https://github.com/dpellier/stencil-react-issue/tree/main

Additional Information

No response

ionitron-bot[bot] commented 9 months ago

Thanks for the issue!

This project is currently maintained for the purposes of supporting Ionic Framework. At this time, only new issues & pull requests that support Ionic Framework will be prioritized. For the latest updates regarding the maintenance status of this project, please see this section of the project's README

ionitron-bot[bot] commented 1 month ago

This issue has been labeled as help wanted. This label is added to issues that we believe would be good for contributors.

If you'd like to work on this issue, please comment here letting us know that you would like to submit a pull request for it. This helps us to keep track of the pull request and make sure there isn't duplicated effort. Thank you!