Skip to content
This repository has been archived by the owner on Jul 21, 2021. It is now read-only.

Commit

Permalink
fix(setValueForStyles): to be compatible with react fiber
Browse files Browse the repository at this point in the history
  • Loading branch information
mroswald committed Jul 11, 2017
1 parent 801d5f8 commit b8f84e2
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions src/vendor/setValueForStyles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ if (process.env.NODE_ENV !== 'production') {

var checkRenderMessage = function(owner) {
if (owner) {
var name = owner.getName();
var name = getComponentName(owner);
if (name) {
return ' Check the render method of `' + name + '`.';
}
Expand All @@ -111,7 +111,7 @@ if (process.env.NODE_ENV !== 'production') {
var warnValidStyle = function(name, value, component) {
var owner;
if (component) {
owner = component._currentElement._owner;
owner = getComponentOwner(component);
}
if (name.indexOf('-') > -1) {
warnHyphenatedStyleName(name, owner);
Expand All @@ -129,6 +129,28 @@ if (process.env.NODE_ENV !== 'production') {

var styleWarnings = {};

function getComponentType(component) {
if (component._currentElement) {
return component._currentElement.type
}

// in case of fiber / react 16
return component.type.displayName;

This comment has been minimized.

Copy link
@gaearon

gaearon Jul 12, 2017

Please use type.displayName || type.name.
ES classes and functions won't have displayName.

This comment has been minimized.

Copy link
@gaearon

gaearon Jul 12, 2017

Btw, in this case judging by the way it's called type will be a string. Because it's a host component.

}

function getComponentName(component) {
return component.getName() || component.displayName;
}

function getComponentOwner(component) {
if (component._currentElement) {
return component._currentElement._owner;
}

// in case of fiber / react 16
return component._debugOwner;
}

/**
* Convert a value into the proper css writable value. The style name `name`
* should be logical (no hyphens)
Expand Down Expand Up @@ -170,8 +192,8 @@ function dangerousStyleValue(name, value, component) {
// Allow '0' to pass through without warning. 0 is already special and
// doesn't require units, so we don't need to warn about it.
if (component && value !== '0') {
var owner = component._currentElement._owner;
var ownerName = owner ? owner.getName() : null;
var owner = getComponentOwner(component);
var ownerName = owner ? getComponentName(owner) : null;
if (ownerName && !styleWarnings[ownerName]) {
styleWarnings[ownerName] = {};
}
Expand All @@ -190,7 +212,7 @@ function dangerousStyleValue(name, value, component) {
'a `%s` tag (owner: `%s`) was passed a numeric string value ' +
'for CSS property `%s` (value: `%s`) which will be treated ' +
'as a unitless number in a future version of React.',
component._currentElement.type,
getComponentType(component),
ownerName || 'unknown',
name,
value
Expand Down

0 comments on commit b8f84e2

Please sign in to comment.