Skip to content

Commit d0648df

Browse files
committed
let webpack-patch work with fiber
1 parent 6ef2688 commit d0648df

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

src/webpack/patch.js

+20-10
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,49 @@
11
const injectionStart = {
22
'16.6': [
33
'if (child.tag === Fragment ? element.type === REACT_FRAGMENT_TYPE : child.elementType === element.type)',
4-
'if (child.tag === Fragment ? element.type === REACT_FRAGMENT_TYPE : hotCompareElements(child.elementType, element.type))'
4+
'if (child.tag === Fragment ? element.type === REACT_FRAGMENT_TYPE : hotCompareElements(child.elementType, element.type, updateChild(child)))'
55
],
66
'16.6-compact': [
77
'if(child.tag===Fragment?element.type===REACT_FRAGMENT_TYPE:child.elementType===element.type)',
8-
'if(child.tag===Fragment?element.type===REACT_FRAGMENT_TYPE:hotCompareElements(child.elementType,element.type))'
8+
'if(child.tag===Fragment?element.type===REACT_FRAGMENT_TYPE:hotCompareElements(child.elementType,element.type, updateChild(child)))'
99
],
1010
'16.4': [
1111
'if (child.tag === Fragment ? element.type === REACT_FRAGMENT_TYPE : child.type === element.type) {',
12-
'if (child.tag === Fragment ? element.type === REACT_FRAGMENT_TYPE : hotCompareElements(child.type, element.type)) {'
12+
'if (child.tag === Fragment ? element.type === REACT_FRAGMENT_TYPE : hotCompareElements(child.type, element.type, updateChild(child))) {'
1313
],
1414
'16.4-compact': [
1515
'if(child.tag===Fragment?element.type===REACT_FRAGMENT_TYPE:child.type===element.type)',
16-
'if(child.tag===Fragment?element.type===REACT_FRAGMENT_TYPE:hotCompareElements(child.type,element.type))'
16+
'if(child.tag===Fragment?element.type===REACT_FRAGMENT_TYPE:hotCompareElements(child.type,element.type, updateChild(child)))'
1717
],
1818
};
1919

2020
const additional = {
2121
'16.6-update': [
2222
'if (current$$1 !== null && current$$1.elementType === element.type) {',
23-
'if (current$$1 !== null && hotCompareElements(current$$1.elementType, element.type)) {'
23+
'if (current$$1 !== null && hotCompareElements(current$$1.elementType, element.type, updateChild(current$$1))) {'
2424
],
2525
'16.6-update-compact': [
2626
'if(current$$1!==null&&current$$1.elementType===element.type)',
27-
'if(current$$1!==null&&hotCompareElements(current$$1.elementType,element.type))'
27+
'if(current$$1!==null&&hotCompareElements(current$$1.elementType,element.type,updateChild(current$$1)))'
2828
],
2929
'16.4-update': [
3030
'if (current !== null && current.type === element.type) {',
31-
'if (current !== null && hotCompareElements(current.type, element.type)) {'
31+
'if (current !== null && hotCompareElements(current.type, element.type, updateChild(current))) {'
3232
],
3333
'16.4-update-compact': [
3434
'if (current!== null&&current.type===element.type)',
35-
'if (current!== null&&hotCompareElements(current.type,element.type))'
35+
'if (current!== null&&hotCompareElements(current.type,element.type,updateChild(current)))'
3636
]
3737
};
3838

3939
const defaultEnd = [
4040
'var ReactDOM = {',
41-
`
41+
`var updateChild = function (child) { return function (newType) {
42+
child.type = newType;
43+
if (child.alternate) {
44+
child.alternate.type = newType;
45+
}
46+
}};
4247
var hotCompareElements = function (oldType, newType) { return oldType === newType };
4348
var ReactDOM = {
4449
setHotElementComparator: function (newComparator) { hotCompareElements = newComparator },
@@ -47,7 +52,12 @@ const defaultEnd = [
4752

4853
const defaultEndCompact = [
4954
'var ReactDOM={',
50-
`
55+
`var updateChild = function (child) { return function (newType) {
56+
child.type = newType;
57+
if (child.alternate) {
58+
child.alternate.type = newType;
59+
}
60+
}};
5161
var hotCompareElements = function (oldType, newType) { return oldType === newType };
5262
var ReactDOM = {
5363
setHotElementComparator: function (newComparator) { hotCompareElements = newComparator },

0 commit comments

Comments
 (0)