Skip to content
This repository was archived by the owner on Nov 19, 2025. It is now read-only.
This repository was archived by the owner on Nov 19, 2025. It is now read-only.

[BUG] Adding a space in front of html causes toReactElement() to keep previous html in memory  #9

@nurdism

Description

@nurdism

This was originally a problem I faced in @ethercorps/sveltekit-og but I have found that the toReactElement() is where problems where cropping up.

toReactElement('<h1>Test 1</h1>')

// produces
{
  type: 'div',
  props: {
    style: {
      display: 'flex',
      flexDirection: 'column',
      width: '100%',
      height: '100%'
    },
    children: [ { type: 'h1', props: { children: 'Test 1' } } ]
  }
}

toReactElement(' <h1>Test 2</h1>')

// produces
{
  type: 'div',
  props: {
    style: {
      display: 'flex',
      flexDirection: 'column',
      width: '100%',
      height: '100%'
    },
    children: [
      { type: 'h1', props: { children: 'Test 1' } },
      { type: 'h1', props: { children: 'Test 2' } }
    ]
  }
}

If you run toReactElement('<h1>Test 1</h1>') again it keeps test 2 in memory

I patched this myself by moving the root const inside the function, but you may have a better solution of how to fix this. You could also trim the HTML string passed to parse maybe?

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions