GithubHelp home page GithubHelp logo

Comments (4)

emmclaughlin avatar emmclaughlin commented on May 3, 2024 3

Hi @LucaDillenburg !

Thank you for the response. I should have definitely defined the problem better in my first post.

The custom element specifically is a html custom element . I'll update the title to reflect this as well.

The specific thing that causes the renderToString/renderToStaticMarkup to diverge is the hyphen (-). You can see the logic here.

I found the easiest way to reproduce would be to add a test case to ReactServerRendering-test.js . The test cause would be:

    it('children should be rendered for custom elements', () => {
      const output = ReactDOMServer.renderToString(
        <my-custom-element-a>
          <my-custom-element-b></my-custom-element-b>
        </my-custom-element-a>,
      );
      expect(output).toBe(`<my-custom-element-a><my-custom-element-b></my-custom-element-b></my-custom-element-a>`);
    });

The above will fail, as the output is actually <my-custom-element-a></my-custom-element-a> because children are skipped during the server rendering.

from react.

sophiebits avatar sophiebits commented on May 3, 2024 1

I believe this was just fixed in #27511! This fix will be in the next release and you can also use the latest canary build (I verified it outputs <custom-element-a><custom-element-b></custom-element-b></custom-element-a>.)

from react.

emmclaughlin avatar emmclaughlin commented on May 3, 2024 1

Thank you all for the help here 🙏

from react.

LucaDillenburg avatar LucaDillenburg commented on May 3, 2024

Hello @emmclaughlin !

I've tried to reproduce your issue, but couldn't yet. Can you provide a minimal reproduction?

For now, this is what I've tested:

import ReactDOMServer from "react-dom/server";

const CustomElementA = ({ children }) => (
    <div>
        <h1>Hello World</h1>
        {children}
    </div>
);

const CustomElementB = ({ children }) => <p>This is a text description.</p>;

const customElements = (
    <CustomElementA>
        <CustomElementB></CustomElementB>
    </CustomElementA>
);

export const staticMarkup = ReactDOMServer.renderToStaticMarkup(customElements);
console.log(staticMarkup);
console.log(ReactDOMServer.renderToString(staticMarkup));

The result is both custom elements being printed:

<div><h1>Hello World</h1><p>This is a text description.</p></div>

from react.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.