Skip to content

Commit a896aff

Browse files
authored
Support new v11 (#577)
1 parent 0921f0c commit a896aff

4 files changed

Lines changed: 30 additions & 4 deletions

File tree

.changeset/mighty-planes-add.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@prefresh/core': patch
3+
---
4+
5+
Add support for new bits in \_\_component of v11

packages/core/src/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const EFFECTS_LIST = '__h';
66
export const RERENDER_COUNT = '__r';
77
export const CATCH_ERROR_OPTION = '__e';
88
export const COMPONENT_DIRTY = '__d';
9+
export const COMPONENT_BITS = '__g';
910
export const VNODE_DOM = '__e';
1011
export const VNODE_CHILDREN = '__k';
1112
export const HOOK_VALUE = '__';

packages/core/src/runtime/catchError.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import { options } from 'preact';
22
import {
33
CATCH_ERROR_OPTION,
4-
COMPONENT_DIRTY,
5-
VNODE_COMPONENT,
64
} from '../constants';
5+
import { isDirty, unsetDirty } from '../utils';
76

87
const oldCatchError = options[CATCH_ERROR_OPTION];
98
options[CATCH_ERROR_OPTION] = (error, vnode, oldVNode) => {
10-
if (vnode[VNODE_COMPONENT] && vnode[VNODE_COMPONENT][COMPONENT_DIRTY]) {
11-
vnode[VNODE_COMPONENT][COMPONENT_DIRTY] = false;
9+
if (isDirty(vnode)) {
10+
unsetDirty(vnode);
1211
}
1312

1413
if (oldCatchError) oldCatchError(error, vnode, oldVNode);

packages/core/src/utils.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { COMPONENT_BITS, COMPONENT_DIRTY, VNODE_COMPONENT } from "./constants"
2+
3+
/** Component is queued for update */
4+
export const COMPONENT_DIRTY_BIT = 1 << 3;
5+
6+
export const isDirty = vnode => {
7+
if (vnode[VNODE_COMPONENT] && vnode[VNODE_COMPONENT][COMPONENT_DIRTY]) {
8+
return true;
9+
}
10+
11+
if (vnode[VNODE_COMPONENT] && (vnode[VNODE_COMPONENT][COMPONENT_BITS] & COMPONENT_DIRTY_BIT)) {
12+
return true;
13+
}
14+
}
15+
16+
export const unsetDirty = vnode => {
17+
if (vnode[VNODE_COMPONENT]) {
18+
if (vnode[VNODE_COMPONENT][COMPONENT_DIRTY]) vnode[VNODE_COMPONENT][COMPONENT_DIRTY] = false;
19+
if (vnode[VNODE_COMPONENT][COMPONENT_BITS]) vnode[VNODE_COMPONENT][COMPONENT_BITS] &= ~COMPONENT_DIRTY_BIT;
20+
}
21+
}

0 commit comments

Comments
 (0)