Skip to content

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

Open
@dpellier

Description

@dpellier

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wanteda good issue for the communitypackage: react@stencil/react-output-target packagetype: bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions