Skip to content
Myr

fix(jsx/dom): Fixed a bug that caused Script elements to turn into Style elements. (#3294)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Taku Amano · committed by GitHub · parent 8f16802 · Browse files · 2 files+28 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+28 added−1 removed

  • tests:+27 added−0 removed
  • other:+1 added−1 removed

2 files+28 added−1 removed

modified:src/jsx/dom/intrinsic-element/components.test.tsx+27 added
748 unmodified lines
749 await new Promise((resolve) => setTimeout(resolve))750 await Promise.resolve()751 expect(root.innerHTML).toBe('<div><div>Content</div><button>Show</button></div>')752 })753754 it('should be inserted into body if has no props', async () => {755 const App = () => {756 return (757 <div>758 <script>alert('Hello')</script>759 </div>760 )761 }762 render(<App />, root)763 expect(document.head.innerHTML).toBe('')764 // prettier-ignore765 expect(root.innerHTML).toBe('<div><script>alert(\'Hello\')</script></div>')766 })767768 it('should be inserted into body if has only src prop', async () => {769 const App = () => {770 return (771 <div>772 <script src='script.js'></script>773 </div>774 )775 }776 render(<App />, root)777 expect(document.head.innerHTML).toBe('')778 expect(root.innerHTML).toBe('<div><script src="script.js"></script></div>')779 })780 })781782 it('accept ref object', async () => {783 const ref = { current: null }
264 unmodified lines
modified:src/jsx/dom/intrinsic-element/components.ts+1 added-1 removed
224 unmodified lines
225226export const script: FC<PropsWithChildren<IntrinsicElements['script']>> = (props) => {227 if (!props || ['src', 'async'].some((k) => !props[k])) {228 return newJSXNode({229 tag: 'style',229 tag: 'script',230 props,231 })232 }233 return documentMetadataTag('script', props, 1, false, true)
149 unmodified lines