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

Undesireable Injection of Commas to Seperate Children Elements #46

Open
LuckyMcBeast opened this issue Sep 10, 2023 · 3 comments
Open

Comments

@LuckyMcBeast
Copy link

LuckyMcBeast commented Sep 10, 2023

The Problem

While using the typed-html library, commas are used to separate Children elements, which get rendered. (Maybe it's something dumb on my end. Was pretty surprised to see the output...)

Use Case

Using typed-html to create email templates which will be sent using Nodemailer via Gmail's SMTP server. Bun is the runtime.

Example

tsconfig.json

"jsx": "react",
"jsxFactory": "elements.createElement"

example.tsx

 const BaseHtml = ({children}: elements.Children) => {
      return `<!DOCTYPE html>
     <html>
      //some starter html
        <body>
          ${children}
        </body>
      </html>`
}

const ExampleTemplate = () => {
    return (
        <BaseHtml>
            <h1>Test</h1>
            <h2>Testing h2</h2>
            <p>Testing paragraph</p>
        </BaseHtml>
    )
}

Expected

<!DOCTYPE html>
     <html>
       ....
        <body>
            <h1>Test</h1>
            <h2>Testing h2</h2>
            <p>Testing paragraph</p>
         <body>
     </html>

Actual

<!DOCTYPE html>
     <html>
       ....
        <body>
            <h1>Test</h1>,<h2>Testing h2</h2>,<p>Testing paragraph</p>
         <body>
     </html>
@LuckyMcBeast
Copy link
Author

Resolved the issue by removing the <body> from the template string and using it as a wrapper directly under <BaseHtml>. Still not completely ideal, but usable. Still curious as to the cause of the comma seperation.

@burdell
Copy link

burdell commented Oct 7, 2023

I also ran into this problem and figured out it was from using multiple children elements instead of a single child.

This rendered the commas between each child:

<Page>
  {categories.map((category) => (
    <div class="list-item">
      <div class="list-name">{category.name}</div>
      <div class="list-description">{category.description}</div>
    </div>
  ))}
</Page>

but making sure that children is a single element did not have the commas:

<Page>
  <div>
    {categories.map((category) => (
      <div class="list-item">
        <div class="list-name">{category.name}</div>
        <div class="list-description">{category.description}</div>
      </div>
    ))}
  </div>
</Page>

@subodhpareek18
Copy link

This removed the commas for me also, but it's not ideal. I am returning a chat ui with multiple messages inside a div. So it's not possible for me to return single child.

I also ran into this problem and figured out it was from using multiple children elements instead of a single child.

This rendered the commas between each child:

<Page>
  {categories.map((category) => (
    <div class="list-item">
      <div class="list-name">{category.name}</div>
      <div class="list-description">{category.description}</div>
    </div>
  ))}
</Page>

but making sure that children is a single element did not have the commas:

<Page>
  <div>
    {categories.map((category) => (
      <div class="list-item">
        <div class="list-name">{category.name}</div>
        <div class="list-description">{category.description}</div>
      </div>
    ))}
  </div>
</Page>

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

No branches or pull requests

3 participants