From da339fb8c8dc52aee070a14366bbfce6d0762b7f Mon Sep 17 00:00:00 2001 From: Nate Hunzaker Date: Fri, 8 Apr 2016 19:37:47 -0400 Subject: [PATCH] Warn when a DOM element has unsupported property This commit updates the logic in ReactDOMUnknownPropertyDevTool such that it will warn when a DOM property not contained in the property whitelist is assigned to a React DOM element. --- .../__tests__/DOMPropertyOperations-test.js | 3 +++ .../devtools/ReactDOMUnknownPropertyDevtool.js | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/renderers/dom/shared/__tests__/DOMPropertyOperations-test.js b/src/renderers/dom/shared/__tests__/DOMPropertyOperations-test.js index 14b72282ae2..b87fcac3acd 100644 --- a/src/renderers/dom/shared/__tests__/DOMPropertyOperations-test.js +++ b/src/renderers/dom/shared/__tests__/DOMPropertyOperations-test.js @@ -391,16 +391,19 @@ describe('DOMPropertyOperations', function() { describe('injectDOMPropertyConfig', function() { it('should support custom attributes', function() { // foobar does not exist yet + spyOn(console, 'error'); expect(DOMPropertyOperations.createMarkupForProperty( 'foobar', 'simple' )).toBe(null); + expect(console.error.argsForCall.length).toBe(1); // foo-* does not exist yet expect(DOMPropertyOperations.createMarkupForProperty( 'foo-xyz', 'simple' )).toBe(null); + expect(console.error.argsForCall.length).toBe(2); // inject foobar DOM property DOMProperty.injection.injectDOMPropertyConfig({ diff --git a/src/renderers/dom/shared/devtools/ReactDOMUnknownPropertyDevtool.js b/src/renderers/dom/shared/devtools/ReactDOMUnknownPropertyDevtool.js index 5adc359063e..149c27ae80b 100644 --- a/src/renderers/dom/shared/devtools/ReactDOMUnknownPropertyDevtool.js +++ b/src/renderers/dom/shared/devtools/ReactDOMUnknownPropertyDevtool.js @@ -19,6 +19,7 @@ var warning = require('warning'); if (__DEV__) { var reactProps = { children: true, + defaultValue: true, dangerouslySetInnerHTML: true, key: true, ref: true, @@ -46,11 +47,10 @@ if (__DEV__) { null ); - // For now, only warn when we have a suggested correction. This prevents - // logging too much when using transferPropsTo. + // Suggest a property name correction if possible warning( standardName == null, - 'Unknown DOM property %s. Did you mean %s?', + 'Unable to assign unsupported DOM property %s. Did you mean %s?', name, standardName ); @@ -63,12 +63,20 @@ if (__DEV__) { null ); + // Suggest an event name correction if possible warning( registrationName == null, - 'Unknown event handler property %s. Did you mean `%s`?', + 'Unable to register unsupported event handler property %s. Did you mean %s?', name, registrationName ); + + // Otherwise at least make it clear that the attributes will be filtered out + warning( + standardName != null || registrationName != null, + 'Unable to assign unsupported DOM property %s.', + name + ); }; }