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: Misleading console.error when rendering components using internals SSR #6073

Closed
3 tasks done
dwirz opened this issue Dec 3, 2024 · 2 comments · Fixed by #6075
Closed
3 tasks done

bug: Misleading console.error when rendering components using internals SSR #6073

dwirz opened this issue Dec 3, 2024 · 2 comments · Fixed by #6075
Labels

Comments

@dwirz
Copy link
Contributor

dwirz commented Dec 3, 2024

Prerequisites

Stencil Version

4.22.3

Current Behavior

Currently, if a component has the formAssociated flag set and uses @AttachInternals(), calling setValidity within the componentDidLoad lifecycle method results in the following console.error message being logged: NOTE: Property form was accessed on...

This occurs because the underlying MockElement implementation proxies all calls to internals which calls console.error. While this behavior might be reasonable in a testing environment—where it can serve as a helpful warning—it becomes irrelevant and misleading in server-side rendering (SSR) contexts.

In SSR, such errors are unnecessary since the ElementInternals API does not apply in the server environment. Addressing this could involve conditionally suppressing these errors during SSR to avoid confusion and ensure a cleaner debugging experience.

Expected Behavior

The console.error shouldn't be logged if the component is rendered in a SSR enviroment.

System Info

System: node 22.11.0
       Build: 1732216626
     Stencil: 4.22.3 🐤
  TypeScript: 5.5.4

Steps to Reproduce

See Description in dwirz/nextjs-stenciljs-example

Code Reproduction URL

https://github.com/dwirz/nextjs-stenciljs-example

Additional Information

Actually it is not a real bug, but it IMO the message should not be displayed if a component is rendered SSR because it is misleading.

The message comes from mock-doc/node.ts#L234

At the moment we add the following workaround check to each component which uses internals:

  componentDidLoad() {
    if (typeof window === "undefined" || window.constructor.name !== "Window") {
      return;
    }
  
    // ...
    
    this.internals.setValidity({});
  }
@ionitron-bot ionitron-bot bot added the triage label Dec 3, 2024
@dwirz dwirz changed the title bug: Misleading console.error when rendering components SSR bug: Misleading console.error when rendering components using internals SSR Dec 3, 2024
@christian-bromann
Copy link
Member

@dwirz thanks for raising the issue. I totally agree, and raised a PR with a fix in #6075

@christian-bromann
Copy link
Member

A fix for this was released in Stencil v4.23.0

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

Successfully merging a pull request may close this issue.

2 participants