-
-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(jsx/dom): improve compatibility with React - The 2024 May Update (…
…#2756) * fix(jsx/dom): fix rerendering of portal elements * fix(jsx/dom): Make more reuse of existing JSX elements, similar to React * feat(jsx/hooks): introduce useInsertionEffect hook * feat(jsx/dom): support SVG kebab-case attributes * fix(jsx/dom): Intrinsic elements can now also be safely Evaluated multiple times for the same element * test: add tests * chore: denoify
- Loading branch information
Showing
16 changed files
with
552 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,16 @@ | ||
import type { Props, JSXNode } from '../base.ts' | ||
import { normalizeIntrinsicElementProps } from '../utils.ts' | ||
|
||
const JSXNodeCompatPrototype = { | ||
type: { | ||
get(this: { tag: string | Function }): string | Function { | ||
return this.tag | ||
}, | ||
}, | ||
ref: { | ||
get(this: { props?: { ref: unknown } }): unknown { | ||
return this.props?.ref | ||
}, | ||
}, | ||
} | ||
import { newJSXNode } from './utils.ts' | ||
|
||
export const jsxDEV = (tag: string | Function, props: Props, key?: string): JSXNode => { | ||
if (typeof tag === 'string') { | ||
normalizeIntrinsicElementProps(props) | ||
} | ||
return Object.defineProperties( | ||
{ | ||
tag, | ||
props, | ||
key, | ||
}, | ||
JSXNodeCompatPrototype | ||
) as JSXNode | ||
return newJSXNode({ | ||
tag, | ||
props, | ||
key, | ||
}) | ||
} | ||
|
||
export const Fragment = (props: Record<string, unknown>): JSXNode => jsxDEV('', props, undefined) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,24 @@ | ||
import type { Props, JSXNode } from '../base.ts' | ||
import { DOM_INTERNAL_TAG } from '../constants.ts' | ||
|
||
export const setInternalTagFlag = (fn: Function): Function => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
;(fn as any)[DOM_INTERNAL_TAG] = true | ||
return fn | ||
} | ||
|
||
const JSXNodeCompatPrototype = { | ||
type: { | ||
get(this: { tag: string | Function }): string | Function { | ||
return this.tag | ||
}, | ||
}, | ||
ref: { | ||
get(this: { props?: { ref: unknown } }): unknown { | ||
return this.props?.ref | ||
}, | ||
}, | ||
} | ||
|
||
export const newJSXNode = (obj: { tag: string | Function; props?: Props; key?: string }): JSXNode => | ||
Object.defineProperties(obj, JSXNodeCompatPrototype) as JSXNode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.