Skip to content

Commit

Permalink
fix: forwardRef to be remounted every frame. React-router to merge co…
Browse files Browse the repository at this point in the history
…mponents
  • Loading branch information
theKashey committed Dec 6, 2018
1 parent 0a28144 commit 3b11866
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions src/reactHotLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
isTypeBlacklisted,
registerComponent,
updateFunctionProxyById,
isRegisteredComponent,
} from './reconciler/proxies'
import configuration from './configuration'
import logger from './logger'
Expand Down Expand Up @@ -59,6 +60,17 @@ const updateForward = (target, { render }) => {
}

export const hotComponentCompare = (oldType, newType, setNewType) => {
if (oldType === newType) {
return true
}

if (
(isRegisteredComponent(oldType) || isRegisteredComponent(newType)) &&
resolveType(oldType) !== resolveType(newType)
) {
return false
}

if (isForwardType({ type: oldType }) && isForwardType({ type: newType })) {
if (areSwappable(oldType.render, newType.render)) {
setNewType(newType)
Expand All @@ -75,10 +87,6 @@ export const hotComponentCompare = (oldType, newType, setNewType) => {
return false
}

if (oldType === newType) {
return true
}

if (areSwappable(newType, oldType)) {
const unwrapFactory = newType[UNWRAP_PROXY]
const oldProxy = unwrapFactory && getProxyByType(unwrapFactory())
Expand Down Expand Up @@ -142,14 +150,19 @@ const reactHotLoader = {
// component got replaced. Need to reconcile
incrementGeneration()

if (isTypeBlacklisted(type) || isTypeBlacklisted(proxy.getCurrent())) {
logger.error(
'React-hot-loader: Cold component',
uniqueLocalName,
'at',
fileName,
'has been updated',
)
if (!reactHotLoader.IS_REACT_MERGE_ENABLED) {
if (
isTypeBlacklisted(type) ||
isTypeBlacklisted(proxy.getCurrent())
) {
logger.error(
'React-hot-loader: Cold component',
uniqueLocalName,
'at',
fileName,
'has been updated',
)
}
}
}

Expand Down

0 comments on commit 3b11866

Please sign in to comment.