Skip to content

Commit

Permalink
fix(omi): inserted node of fragment disappears in installed function
Browse files Browse the repository at this point in the history
  • Loading branch information
dntzhang committed Nov 10, 2023
1 parent f3839ff commit 34ab7ad
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/omi/README.md
Expand Up @@ -323,7 +323,7 @@ define('my-app', class extends withTwind(Component) {
## Contributors

<a href="https://github.com/Tencent/omi/graphs/contributors">
<img src="https://omi.cdn-go.cn/contributors.png" />
<img src="https://raw.githubusercontent.com/Tencent/omi/master/assets/contributors.png" />
</a>

## License
Expand Down
37 changes: 37 additions & 0 deletions packages/omi/examples/ref.tsx
@@ -0,0 +1,37 @@
import { render, tag, Component, h, bind, createRef } from '@/index'

@tag('counter-demo')
class CounterDemo extends Component {
count: number = 0

static css = 'span { color: red; }'

@bind
add() {
this.count++
this.update()

}

installed() {
const p = document.createElement('p');
p.textContent = 'hello'
// 更新后消失
this.refSpan.current.appendChild(p)
}

refSpan = createRef()

render() {
return (
<>
<span>{this.count} <button onClick={this.add}>+</button></span>
<div>
<div ref={this.refSpan}></div>
</div>
</>
)
}
}

render(<counter-demo />, document.body)
2 changes: 1 addition & 1 deletion packages/omi/package.json
@@ -1,6 +1,6 @@
{
"name": "omi",
"version": "7.3.5",
"version": "7.3.6",
"scripts": {
"start": "vite",
"dev-vite": "vite",
Expand Down
7 changes: 6 additions & 1 deletion packages/omi/src/diff.ts
Expand Up @@ -29,7 +29,11 @@ export function diff(dom: ExtendedElement | ExtendedElement[] | null, vnode: VNo
isSvgMode = parent != null && (parent as Element as SVGElement).ownerSVGElement !== undefined

// hydration is indicated by the existing element to be diffed not having a prop cache
hydrating = dom != null && !('prevProps' in dom)
// hydrating = dom != null && !('prevProps' in dom)

// SSR is currently not supported
hydrating = false

}

if (isArray(vnode)) {
Expand Down Expand Up @@ -227,6 +231,7 @@ function innerDiffNode(dom: ExtendedElement, vchildren: VNode[], isHydrating: bo
vlen && prevProps
? prevProps.key
: null

if (key != null) {
keyedLen++
keyed[key as string] = child as Element
Expand Down
2 changes: 1 addition & 1 deletion packages/omi/src/index.ts
Expand Up @@ -10,6 +10,6 @@ export { Signal } from './signal'
export { css } from './css-tag'
export { mixin } from './options'
export { registerDirective } from './directive'
export const version = '7.3.5'
export const version = '7.3.6'


0 comments on commit 34ab7ad

Please sign in to comment.