Skip to content

Commit

Permalink
Fixes #108
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-kinokon committed Aug 23, 2024
1 parent c80a80d commit 6e0e7e8
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 67 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 8.1.5
- Fixes #108: Class components are now differentiated from functional components by `.isComponent` instead of `.prototype.isReactComponent`, fixing an issue with terser.

# 8.1.4
- Fixes #104: Class Components do not populate their ref attribute.

# 8.1.3
- Merged #101.

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jsx-dom",
"version": "8.1.4",
"version": "8.1.5",
"description": "JSX to document.createElement.",
"main": "index.js",
"module": "index.js",
Expand All @@ -25,7 +25,7 @@
"build"
],
"resolutions": {
"@babel/types": "^7.21.0"
"@babel/types": "^7.25.4"
},
"devDependencies": {
"@babel/core": "^7.25.2",
Expand Down
94 changes: 44 additions & 50 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 3 additions & 7 deletions src/jsx-dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,15 @@ export function Fragment(attr: { children: (JSX.Element | JSX.Element)[] }) {
}

export class Component {
static isComponent = true

constructor(readonly props: any) {}

render() {
return null
}
}

/* @__PURE__ */ Object.defineProperties(Component.prototype, {
isReactComponent: {
value: true,
},
})

function initComponentClass(Class: ComponentClass, attr, children) {
attr = { ...attr, children }
const instance = new Class(attr)
Expand Down Expand Up @@ -208,7 +204,7 @@ export function attachRef<T = Node>(ref: any | undefined, node: T) {
}

function appendChild(
child: any[] | string | number | ShadowRootContainer | null | Element,
child: any[] | string | number | ShadowRootContainer | null | Element | DocumentFragment,
node: Node
) {
if (isArrayLike(child)) {
Expand Down
7 changes: 4 additions & 3 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ export function isFunction(val: any): val is Function {
return typeof val === "function"
}

export function isComponentClass(Component: Function): Component is ComponentClass {
const { prototype } = Component
return !!(prototype && prototype.isReactComponent)
export function isComponentClass(
Component: Function & { isComponent?: boolean }
): Component is ComponentClass {
return !!(Component && Component.isComponent)
}

export function isArrayLike(obj: any): obj is ArrayLike<any> {
Expand Down
Loading

0 comments on commit 6e0e7e8

Please sign in to comment.