Skip to content

Commit

Permalink
fix(jsx/dom): Fixed a bug that caused Script elements to turn into St…
Browse files Browse the repository at this point in the history
…yle elements. (#3294)
  • Loading branch information
usualoma authored Aug 19, 2024
1 parent 8f16802 commit e6459e7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions src/jsx/dom/intrinsic-element/components.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,33 @@ describe('intrinsic element', () => {
await Promise.resolve()
expect(root.innerHTML).toBe('<div><div>Content</div><button>Show</button></div>')
})

it('should be inserted into body if has no props', async () => {
const App = () => {
return (
<div>
<script>alert('Hello')</script>
</div>
)
}
render(<App />, root)
expect(document.head.innerHTML).toBe('')
// prettier-ignore
expect(root.innerHTML).toBe('<div><script>alert(\'Hello\')</script></div>')
})

it('should be inserted into body if has only src prop', async () => {
const App = () => {
return (
<div>
<script src='script.js'></script>
</div>
)
}
render(<App />, root)
expect(document.head.innerHTML).toBe('')
expect(root.innerHTML).toBe('<div><script src="script.js"></script></div>')
})
})

it('accept ref object', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/jsx/dom/intrinsic-element/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export const title: FC<PropsWithChildren> = (props) => {
export const script: FC<PropsWithChildren<IntrinsicElements['script']>> = (props) => {
if (!props || ['src', 'async'].some((k) => !props[k])) {
return newJSXNode({
tag: 'style',
tag: 'script',
props,
})
}
Expand Down

0 comments on commit e6459e7

Please sign in to comment.