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: Request for JSX Support for HTML Comments () in React #31889

Open
robertpanvip opened this issue Dec 23, 2024 · 1 comment
Open

Bug: Request for JSX Support for HTML Comments () in React #31889

robertpanvip opened this issue Dec 23, 2024 · 1 comment
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug

Comments

@robertpanvip
Copy link

robertpanvip commented Dec 23, 2024

Description

Currently, React does not support rendering HTML comments () directly in JSX. This limitation makes it challenging to implement certain use cases.

For instance, in React 19, findDOMNode has been deprecated, but in some scenarios, we still need similar functionality, such as retrieving a component’s DOM reference or marking specific nodes. A potential solution could be using comment nodes () as placeholders to enable subsequent DOM operations involving these nodes.

Feature Request

We hope React could support rendering comment nodes directly in JSX, such as:

jsx

<div>  
  <!-- This is a comment node -->  
</div>  

Rendering as:

html

<div>  
  <!-- This is a comment node -->  
</div>  

Why This Is Needed

Enhance DOM Manipulation Capabilities
Comment nodes can serve as lightweight markers for advanced DOM operations, such as dynamically inserting content or replacing deprecated findDOMNode functionality.

Flexibility and Compatibility
In some legacy systems, comment nodes are used to identify specific logic. Supporting this feature would allow developers to migrate old projects more easily or implement more complex functionality.

Improve Developer Experience
Allowing HTML comments in JSX can make the code more readable while helping developers document and debug specific logic directly within their JSX code.

Possible Alternatives

If supporting directly is not feasible, React could introduce a component like :
jsx

<div>  
  <Comment>This is a comment node</Comment>  
</div> 

Rendering as:

html

<div>  
  <!-- This is a comment node -->  
</div>  

Conclusion

We kindly request the team to consider this feature.

@robertpanvip robertpanvip added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Dec 23, 2024
@Antraxmin
Copy link

I would like to work on this feature. kindly assign it to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug
Projects
None yet
Development

No branches or pull requests

2 participants