Skip to content

Commit 62bc67e

Browse files
committed
fix: resolve all components to their last versions, #1342
1 parent 7500b0e commit 62bc67e

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/internal/getReactStack.js

+9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import ReactDOM from 'react-dom';
44
import hydrateFiberStack from './stack/hydrateFiberStack';
55
import hydrateLegacyStack from './stack/hydrateLegacyStack';
66
import { getInternalInstance } from './reactUtils';
7+
import { resolveType } from '../reconciler/resolver';
78

89
function getReactStack(instance) {
910
const rootNode = getInternalInstance(instance);
@@ -30,10 +31,18 @@ const markUpdate = ({ fiber }) => {
3031
if (!fiber || typeof fiber.type === 'string') {
3132
return;
3233
}
34+
35+
const mostResentType = resolveType(fiber.type) || fiber.type;
36+
if (fiber.elementType === fiber.type) {
37+
fiber.elementType = mostResentType;
38+
}
39+
fiber.type = mostResentType;
40+
3341
fiber.expirationTime = 1;
3442
if (fiber.alternate) {
3543
fiber.alternate.expirationTime = 1;
3644
fiber.alternate.type = fiber.type;
45+
fiber.alternate.elementType = fiber.elementType;
3746
}
3847

3948
if (fiber.memoizedProps && typeof fiber.memoizedProps === 'object') {

src/reconciler/resolver.js

+19-1
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,30 @@ export function resolveNotComponent(type) {
6666
return undefined;
6767
}
6868

69+
export const getLatestTypeVersion = type => {
70+
const existingProxy = getProxyByType(type);
71+
return existingProxy && existingProxy.getCurrent && existingProxy.getCurrent();
72+
};
73+
6974
export const resolveSimpleType = type => {
7075
if (!type) {
7176
return type;
7277
}
7378

74-
return resolveProxy(type) || resolveUtility(type) || type;
79+
const simpleResult = resolveProxy(type) || resolveUtility(type) || resolveNotComponent(type);
80+
if (simpleResult) {
81+
return simpleResult;
82+
}
83+
84+
const lastType = getLatestTypeVersion(type);
85+
86+
// only lazy loaded components any now failing into this branch
87+
88+
// if (lastType && lastType !== type) {
89+
// console.warn('RHL: used type', type, 'is obsolete. Something is wrong with HMR.');
90+
// }
91+
92+
return lastType || type;
7593
};
7694

7795
export const resolveType = (type, options = {}) => {

0 commit comments

Comments
 (0)