Skip to content

Commit

Permalink
fix: resolve all components to their last versions, #1342
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed Sep 22, 2019
1 parent 7500b0e commit 62bc67e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/internal/getReactStack.js
Expand Up @@ -4,6 +4,7 @@ import ReactDOM from 'react-dom';
import hydrateFiberStack from './stack/hydrateFiberStack';
import hydrateLegacyStack from './stack/hydrateLegacyStack';
import { getInternalInstance } from './reactUtils';
import { resolveType } from '../reconciler/resolver';

function getReactStack(instance) {
const rootNode = getInternalInstance(instance);
Expand All @@ -30,10 +31,18 @@ const markUpdate = ({ fiber }) => {
if (!fiber || typeof fiber.type === 'string') {
return;
}

const mostResentType = resolveType(fiber.type) || fiber.type;
if (fiber.elementType === fiber.type) {
fiber.elementType = mostResentType;
}
fiber.type = mostResentType;

fiber.expirationTime = 1;
if (fiber.alternate) {
fiber.alternate.expirationTime = 1;
fiber.alternate.type = fiber.type;
fiber.alternate.elementType = fiber.elementType;
}

if (fiber.memoizedProps && typeof fiber.memoizedProps === 'object') {
Expand Down
20 changes: 19 additions & 1 deletion src/reconciler/resolver.js
Expand Up @@ -66,12 +66,30 @@ export function resolveNotComponent(type) {
return undefined;
}

export const getLatestTypeVersion = type => {
const existingProxy = getProxyByType(type);
return existingProxy && existingProxy.getCurrent && existingProxy.getCurrent();
};

export const resolveSimpleType = type => {
if (!type) {
return type;
}

return resolveProxy(type) || resolveUtility(type) || type;
const simpleResult = resolveProxy(type) || resolveUtility(type) || resolveNotComponent(type);
if (simpleResult) {
return simpleResult;
}

const lastType = getLatestTypeVersion(type);

// only lazy loaded components any now failing into this branch

// if (lastType && lastType !== type) {
// console.warn('RHL: used type', type, 'is obsolete. Something is wrong with HMR.');
// }

return lastType || type;
};

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

0 comments on commit 62bc67e

Please sign in to comment.