File tree Expand file tree Collapse file tree 3 files changed +30
-2
lines changed
Expand file tree Collapse file tree 3 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -16,8 +16,10 @@ import {setAutoComponent} from '../states-collector'
1616import { HashType , isVirtualElement , VirtualElement } from '../../jsx/VirtualElement'
1717import { includeStateUsage , makeContext } from './state-usage'
1818import { escapeHTML } from 'bun'
19+ import { UnsafeHTML } from 'src/jsx/insert-html'
1920
2021let currentComponentHash
22+
2123export function getCurrentComponentHash ( ) {
2224 return currentComponentHash
2325}
@@ -141,7 +143,11 @@ export default class TemplateBuilder {
141143 }
142144
143145 private stringifyTextNode ( value : StringifiableType ) : [ string , ServerTemplateTextNodeType ] {
144- const string = escapeHTML ( stringifyValue ( value ) )
146+ let string
147+ if ( value instanceof UnsafeHTML )
148+ string = value . valueOf ( )
149+ else
150+ string = escapeHTML ( stringifyValue ( value ) )
145151 return [
146152 `[0"${ string } "]` ,
147153 { type : 'text' , content : string }
Original file line number Diff line number Diff line change 1+ import { unsafeInsertHtmlDoNotUse } from '../../insert-html'
2+
13export default function Html ( { ...props } : JSX . IntrinsicElements [ 'html' ] ) {
24 return < >
3- { '<!DOCTYPE html>' }
5+ { unsafeInsertHtmlDoNotUse ( '<!DOCTYPE html>' ) }
46 < html { ...props } > { props . children } </ html >
57 </ >
68}
Original file line number Diff line number Diff line change 1+ import { HashType } from './VirtualElement'
2+ import { getCurrentComponentHash } from '../compiler/template/template-builder'
3+
4+ export function unsafeInsertHtmlDoNotUse ( value : string ) {
5+ return new UnsafeHTML ( value )
6+ }
7+
8+ export class UnsafeHTML {
9+ private readonly componentHash : HashType
10+ private readonly value : string
11+
12+ constructor ( value : string ) {
13+ this . componentHash = getCurrentComponentHash ( )
14+ this . value = value
15+ }
16+
17+ valueOf ( ) : UnsafeHTML [ 'value' ] {
18+ return this . value
19+ }
20+ }
You can’t perform that action at this time.
0 commit comments