react/packages/react-dom/src/shared/ReactDOMUnknownPropertyHook.js

303 lines
8.9 KiB
JavaScript
Raw Normal View History

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import {
registrationNameModules,
possibleRegistrationNames,
} from 'legacy-events/EventPluginRegistry';
import warning from 'shared/warning';
import {
ATTRIBUTE_NAME_CHAR,
BOOLEAN,
Refactor DOM attribute code (take two) (#11815) * Harden tests around init/addition/update/removal of aliased attributes I noticed some patterns weren't being tested. * Call setValueForProperty() for null and undefined The branching before the call is unnecessary because setValueForProperty() already has an internal branch that delegates to deleteValueForProperty() for null and undefined through the shouldIgnoreValue() check. The goal is to start unifying these methods because their separation doesn't reflect the current behavior (e.g. for unknown properties) anymore, and obscures what actually happens with different inputs. * Inline deleteValueForProperty() into setValueForProperty() Now we don't read propertyInfo twice in this case. I also dropped a few early returns. I added them a while ago when we had Stack-only tracking of DOM operations, and some operations were being counted twice because of how this code is structured. This isn't a problem anymore (both because we don't track operations, and because I've just inlined this method call). * Inline deleteValueForAttribute() into setValueForAttribute() The special cases for null and undefined already exist in setValueForAttribute(). * Delete some dead code * Make setValueForAttribute() a branch of setValueForProperty() Their naming is pretty confusing by now. For example setValueForProperty() calls setValueForAttribute() when shouldSetAttribute() is false (!). I want to refactor (as in, inline and then maybe factor it out differently) the relation between them. For now, I'm consolidating the callers to use setValueForProperty(). * Make it more obvious where we skip and when we reset attributes The naming of these methods is still very vague and conflicting in some cases. Will need further work. * Rewrite setValueForProperty() with early exits This makes the flow clearer in my opinion. * Move shouldIgnoreValue() into DOMProperty It was previously duplicated. It's also suspiciously similar in purpose to shouldTreatAttributeValueAsNull() so I want to see if there is a way to unify them. * Use more specific methods for testing validity * Unify shouldTreatAttributeValueAsNull() and shouldIgnoreValue() * Remove shouldSetAttribute() Its naming was confusing and it was used all over the place instead of more specific checks. Now that we only have one call site, we might as well inline and get rid of it. * Remove unnecessary condition * Remove another unnecessary condition * Add Flow coverage * Oops * Fix lint (ESLint complains about Flow suppression) * Fix treatment of Symbol/Function values on boolean attributes They weren't being properly skipped because of the early return. I added tests for this case. * Avoid getPropertyInfo() calls I think this PR looks worse on benchmarks because we have to read propertyInfo in different places. Originally I tried to get rid of propertyInfo, but looks like it's important for performance after all. So now I'm going into the opposite direction, and precompute propertyInfo as early as possible, and then just pass it around. This way we can avoid extra lookups but keep functions nice and modular. * Pass propertyInfo as argument to getValueForProperty() It always exists because this function is only called for known properties. * Make it clearer this branch is boolean-specific I wrote this and then got confused myself. * Memoize whether propertyInfo accepts boolean value Since we run these checks for all booleans, might as well remember it. * Fix a crash when numeric property is given a Symbol * Record attribute table The changes reflect that SSR doesn't crash with symbols anymore (and just warns, consistently with the client). * Refactor attribute initialization Instead of using flags, explicitly group similar attributes/properties. * Optimization: we know built-in attributes are never invalid * Use strict comparison * Rename methods for clarity * Lint nit * Minor tweaks * Document all the different attribute types
2017-12-11 00:58:38 +08:00
RESERVED,
shouldRemoveAttributeWithWarning,
getPropertyInfo,
} from './DOMProperty';
import isCustomComponent from './isCustomComponent';
import possibleStandardNames from './possibleStandardNames';
Refactor Debug Frames to Enable Renderers to Provide Custom Logic (#10105) * Extract the top element frame from ReactDebugCurrentFrame This is part of a larger refactor to decouple stack addendums. All renderers have their own way of getting the stack of the currently executing components. There is one special case in Element Validator that adds an additional line for the element being validated. This commit moves that special case in into the validator. There is another case where it looked like this was used in shallow renderer but this is actually something different. It is part of the component stack. It just happens to be that shallow renderer has a simpler implementation of the component stack that just happens to be a single element. This will let us decouple the implementation to get a stack from ReactDebugCurrentFrame and put that in each renderer. * Stop using ReactComponentTreeHook for Fiber Currently we fall back to ReactCurrentOwner in ReactComponentTreeHook for stack addendums. We shouldn't need to because we should use ReactDebugCurrrentFiber. Ensure we always set both ReactDebugCurrentFiber and ReactDebugCurrentFrame so that we can rely on these for all stacks. * Make ReactDebugCurrentFrame implementation independent Introduced ReactDebugCurrentStack for the Stack renderer which does the same thing as ReactDebugCurrentFiber. ReactDebugCurrentFrame no longer keeps track of the current fiber/debug id. That's handled by the individual renderers. Instead, it is now used to keep track of the current *implementation* of the current stack frame. That way it is decoupled from the specifics of the renderers. There can be multiple renderers in a context. What matters is which one is currently executing a debuggable context (such as a render function). * Add debug frames to ReactPartialRenderer (ssr) Basic functionality. * Add shared modules to shallow renderer This is now needed because we share describeComponentFrame.
2017-07-15 06:36:24 +08:00
let validateProperty = () => {};
if (__DEV__) {
const warnedProperties = {};
const hasOwnProperty = Object.prototype.hasOwnProperty;
const EVENT_NAME_REGEX = /^on./;
const INVALID_EVENT_NAME_REGEX = /^on[^A-Z]/;
const rARIA = new RegExp('^(aria)-[' + ATTRIBUTE_NAME_CHAR + ']*$');
const rARIACamel = new RegExp('^(aria)[A-Z][' + ATTRIBUTE_NAME_CHAR + ']*$');
validateProperty = function(tagName, name, value, canUseEventSystem) {
if (hasOwnProperty.call(warnedProperties, name) && warnedProperties[name]) {
return true;
}
Custom Attributes Scenario 2: Write badly cased attributes. Remove most of whitelist. (#10385) * Allow custom attributes. Add flag to toggle custom attribute behavior * Update custom attribute logic - Only allow string attributes - Remove custom attribute feature flag - Add additional tests for data, aria, and custom attributes * Allow numbers and booleans custom attributes. Cut isCustomAttribute * Cover objects with custom attributes in warning test * Rename DOMProperty.isWriteable to shouldSetAttribute * Rework conditions in shouldSetProperty to avoid edge cases * Update unknown property warning to include custom attribute information * Remove ref and key from reserved props * Ensure SSR test coverage for DOMProperty injections * Add ajaxify attribute for internal FB support * Ajaxify is a stringifiable object attribute * Remove non-case sensitive standard attributes. Make ARIA hook dev only. * Update test name for custom attributes on custom elements * Remove SSR custom injection test * Remove case sensitive props * Remove onAfterResetModules hooks in SSR render tests * Add back a few attributes and explain why they are needed * Remove possibleStandardNames from DOMProperty.js * Fix typo in HTMLPropertyConfig comment * Remove duplicative comment * Add back loop boolean property * Do not allow assignment of attributes that are aliased * Update custom attribute test to check value, not just presence * Address case where class is assigned as an attribute on custom elements. Improve SSR tests * Cover cases where className and for are given to custom elements * Remove unnecessary spys on console.error. Reduce extra space in tests * Cover cased custom attributes in SSR tests * Custom attributes are case sensitive * Allow uppercase letters in custom attributes. Address associated edge cases * Allow improperly cased aliased attributes. Add additional tests * Handle special properties like onFocusOut * Add some comments to document where casing matters. Remove DOMPropertyNames * Fix spelling mistake in ajaxify HTML property comment * Make ARIA enforcement dev-only * Remove alias test that covers multiple aliases for one property * Fix typo in comment * Build SVG aliases dynamically * Remove unused DOMPropertyNames reference * Do not translate bad casings of aliased attributes - classname writes to the DOM as classname - class does not write to the DOM - cLASS does not write to the DOM - arabic-form does not write to the DOM * Revise the way custom booleans are treated - Custom attributes can not have boolean values unless they are aria or data attributes - Attributes with boolean values have been added back to the whitelist - Warnings now exclude booleans from supported types - Associated test coverage * Add developer warnings for NaN and ARIA hooks * Use string comparison instead of regex to check for data and aria attributes. * Warn about unsupported properties without case sensitivity * Remove attributes that are updated to invalid values * Support object property values with toString methods. Allow boolean props to coerce objects * Add back ajaxify test * Address bad references in ReactDOMComponent-test. Format. * Revert changes to the docs We'll update them separately * Allow all objects and pass incorrect aliases
2017-08-16 00:00:45 +08:00
const lowerCasedName = name.toLowerCase();
Run 90% of tests on compiled bundles (both development and production) (#11633) * Extract Jest config into a separate file * Refactor Jest scripts directory structure Introduces a more consistent naming scheme. * Add yarn test-bundles and yarn test-prod-bundles Only files ending with -test.public.js are opted in (so far we don't have any). * Fix error decoding for production bundles GCC seems to remove `new` from `new Error()` which broke our proxy. * Build production version of react-noop-renderer This lets us test more bundles. * Switch to blacklist (exclude .private.js tests) * Rename tests that are currently broken against bundles to *-test.internal.js Some of these are using private APIs. Some have other issues. * Add bundle tests to CI * Split private and public ReactJSXElementValidator tests * Remove internal deps from ReactServerRendering-test and make it public * Only run tests directly in __tests__ This lets us share code between test files by placing them in __tests__/utils. * Remove ExecutionEnvironment dependency from DOMServerIntegrationTest It's not necessary since Stack. * Split up ReactDOMServerIntegration into test suite and utilities This enables us to further split it down. Good both for parallelization and extracting public parts. * Split Fragment tests from other DOMServerIntegration tests This enables them to opt other DOMServerIntegration tests into bundle testing. * Split ReactDOMServerIntegration into different test files It was way too slow to run all these in sequence. * Don't reset the cache twice in DOMServerIntegration tests We used to do this to simulate testing separate bundles. But now we actually *do* test bundles. So there is no need for this, as it makes tests slower. * Rename test-bundles* commands to test-build* Also add test-prod-build as alias for test-build-prod because I keep messing them up. * Use regenerator polyfill for react-noop This fixes other issues and finally lets us run ReactNoop tests against a prod bundle. * Run most Incremental tests against bundles Now that GCC generator issue is fixed, we can do this. I split ErrorLogging test separately because it does mocking. Other error handling tests don't need it. * Update sizes * Fix ReactMount test * Enable ReactDOMComponent test * Fix a warning issue uncovered by flat bundle testing With flat bundles, we couldn't produce a good warning for <div onclick={}> on SSR because it doesn't use the event system. However the issue was not visible in normal Jest runs because the event plugins have been injected by the time the test ran. To solve this, I am explicitly passing whether event system is available as an argument to the hook. This makes the behavior consistent between source and bundle tests. Then I change the tests to document the actual logic and _attempt_ to show a nice message (e.g. we know for sure `onclick` is a bad event but we don't know the right name for it on the server so we just say a generic message about camelCase naming convention).
2017-11-24 01:44:58 +08:00
if (lowerCasedName === 'onfocusin' || lowerCasedName === 'onfocusout') {
warning(
false,
Run 90% of tests on compiled bundles (both development and production) (#11633) * Extract Jest config into a separate file * Refactor Jest scripts directory structure Introduces a more consistent naming scheme. * Add yarn test-bundles and yarn test-prod-bundles Only files ending with -test.public.js are opted in (so far we don't have any). * Fix error decoding for production bundles GCC seems to remove `new` from `new Error()` which broke our proxy. * Build production version of react-noop-renderer This lets us test more bundles. * Switch to blacklist (exclude .private.js tests) * Rename tests that are currently broken against bundles to *-test.internal.js Some of these are using private APIs. Some have other issues. * Add bundle tests to CI * Split private and public ReactJSXElementValidator tests * Remove internal deps from ReactServerRendering-test and make it public * Only run tests directly in __tests__ This lets us share code between test files by placing them in __tests__/utils. * Remove ExecutionEnvironment dependency from DOMServerIntegrationTest It's not necessary since Stack. * Split up ReactDOMServerIntegration into test suite and utilities This enables us to further split it down. Good both for parallelization and extracting public parts. * Split Fragment tests from other DOMServerIntegration tests This enables them to opt other DOMServerIntegration tests into bundle testing. * Split ReactDOMServerIntegration into different test files It was way too slow to run all these in sequence. * Don't reset the cache twice in DOMServerIntegration tests We used to do this to simulate testing separate bundles. But now we actually *do* test bundles. So there is no need for this, as it makes tests slower. * Rename test-bundles* commands to test-build* Also add test-prod-build as alias for test-build-prod because I keep messing them up. * Use regenerator polyfill for react-noop This fixes other issues and finally lets us run ReactNoop tests against a prod bundle. * Run most Incremental tests against bundles Now that GCC generator issue is fixed, we can do this. I split ErrorLogging test separately because it does mocking. Other error handling tests don't need it. * Update sizes * Fix ReactMount test * Enable ReactDOMComponent test * Fix a warning issue uncovered by flat bundle testing With flat bundles, we couldn't produce a good warning for <div onclick={}> on SSR because it doesn't use the event system. However the issue was not visible in normal Jest runs because the event plugins have been injected by the time the test ran. To solve this, I am explicitly passing whether event system is available as an argument to the hook. This makes the behavior consistent between source and bundle tests. Then I change the tests to document the actual logic and _attempt_ to show a nice message (e.g. we know for sure `onclick` is a bad event but we don't know the right name for it on the server so we just say a generic message about camelCase naming convention).
2017-11-24 01:44:58 +08:00
'React uses onFocus and onBlur instead of onFocusIn and onFocusOut. ' +
'All React events are normalized to bubble, so onFocusIn and onFocusOut ' +
'are not needed/supported by React.',
);
Custom Attributes Scenario 2: Write badly cased attributes. Remove most of whitelist. (#10385) * Allow custom attributes. Add flag to toggle custom attribute behavior * Update custom attribute logic - Only allow string attributes - Remove custom attribute feature flag - Add additional tests for data, aria, and custom attributes * Allow numbers and booleans custom attributes. Cut isCustomAttribute * Cover objects with custom attributes in warning test * Rename DOMProperty.isWriteable to shouldSetAttribute * Rework conditions in shouldSetProperty to avoid edge cases * Update unknown property warning to include custom attribute information * Remove ref and key from reserved props * Ensure SSR test coverage for DOMProperty injections * Add ajaxify attribute for internal FB support * Ajaxify is a stringifiable object attribute * Remove non-case sensitive standard attributes. Make ARIA hook dev only. * Update test name for custom attributes on custom elements * Remove SSR custom injection test * Remove case sensitive props * Remove onAfterResetModules hooks in SSR render tests * Add back a few attributes and explain why they are needed * Remove possibleStandardNames from DOMProperty.js * Fix typo in HTMLPropertyConfig comment * Remove duplicative comment * Add back loop boolean property * Do not allow assignment of attributes that are aliased * Update custom attribute test to check value, not just presence * Address case where class is assigned as an attribute on custom elements. Improve SSR tests * Cover cases where className and for are given to custom elements * Remove unnecessary spys on console.error. Reduce extra space in tests * Cover cased custom attributes in SSR tests * Custom attributes are case sensitive * Allow uppercase letters in custom attributes. Address associated edge cases * Allow improperly cased aliased attributes. Add additional tests * Handle special properties like onFocusOut * Add some comments to document where casing matters. Remove DOMPropertyNames * Fix spelling mistake in ajaxify HTML property comment * Make ARIA enforcement dev-only * Remove alias test that covers multiple aliases for one property * Fix typo in comment * Build SVG aliases dynamically * Remove unused DOMPropertyNames reference * Do not translate bad casings of aliased attributes - classname writes to the DOM as classname - class does not write to the DOM - cLASS does not write to the DOM - arabic-form does not write to the DOM * Revise the way custom booleans are treated - Custom attributes can not have boolean values unless they are aria or data attributes - Attributes with boolean values have been added back to the whitelist - Warnings now exclude booleans from supported types - Associated test coverage * Add developer warnings for NaN and ARIA hooks * Use string comparison instead of regex to check for data and aria attributes. * Warn about unsupported properties without case sensitivity * Remove attributes that are updated to invalid values * Support object property values with toString methods. Allow boolean props to coerce objects * Add back ajaxify test * Address bad references in ReactDOMComponent-test. Format. * Revert changes to the docs We'll update them separately * Allow all objects and pass incorrect aliases
2017-08-16 00:00:45 +08:00
warnedProperties[name] = true;
return true;
}
Run 90% of tests on compiled bundles (both development and production) (#11633) * Extract Jest config into a separate file * Refactor Jest scripts directory structure Introduces a more consistent naming scheme. * Add yarn test-bundles and yarn test-prod-bundles Only files ending with -test.public.js are opted in (so far we don't have any). * Fix error decoding for production bundles GCC seems to remove `new` from `new Error()` which broke our proxy. * Build production version of react-noop-renderer This lets us test more bundles. * Switch to blacklist (exclude .private.js tests) * Rename tests that are currently broken against bundles to *-test.internal.js Some of these are using private APIs. Some have other issues. * Add bundle tests to CI * Split private and public ReactJSXElementValidator tests * Remove internal deps from ReactServerRendering-test and make it public * Only run tests directly in __tests__ This lets us share code between test files by placing them in __tests__/utils. * Remove ExecutionEnvironment dependency from DOMServerIntegrationTest It's not necessary since Stack. * Split up ReactDOMServerIntegration into test suite and utilities This enables us to further split it down. Good both for parallelization and extracting public parts. * Split Fragment tests from other DOMServerIntegration tests This enables them to opt other DOMServerIntegration tests into bundle testing. * Split ReactDOMServerIntegration into different test files It was way too slow to run all these in sequence. * Don't reset the cache twice in DOMServerIntegration tests We used to do this to simulate testing separate bundles. But now we actually *do* test bundles. So there is no need for this, as it makes tests slower. * Rename test-bundles* commands to test-build* Also add test-prod-build as alias for test-build-prod because I keep messing them up. * Use regenerator polyfill for react-noop This fixes other issues and finally lets us run ReactNoop tests against a prod bundle. * Run most Incremental tests against bundles Now that GCC generator issue is fixed, we can do this. I split ErrorLogging test separately because it does mocking. Other error handling tests don't need it. * Update sizes * Fix ReactMount test * Enable ReactDOMComponent test * Fix a warning issue uncovered by flat bundle testing With flat bundles, we couldn't produce a good warning for <div onclick={}> on SSR because it doesn't use the event system. However the issue was not visible in normal Jest runs because the event plugins have been injected by the time the test ran. To solve this, I am explicitly passing whether event system is available as an argument to the hook. This makes the behavior consistent between source and bundle tests. Then I change the tests to document the actual logic and _attempt_ to show a nice message (e.g. we know for sure `onclick` is a bad event but we don't know the right name for it on the server so we just say a generic message about camelCase naming convention).
2017-11-24 01:44:58 +08:00
// We can't rely on the event system being injected on the server.
if (canUseEventSystem) {
if (registrationNameModules.hasOwnProperty(name)) {
return true;
}
const registrationName = possibleRegistrationNames.hasOwnProperty(
Run 90% of tests on compiled bundles (both development and production) (#11633) * Extract Jest config into a separate file * Refactor Jest scripts directory structure Introduces a more consistent naming scheme. * Add yarn test-bundles and yarn test-prod-bundles Only files ending with -test.public.js are opted in (so far we don't have any). * Fix error decoding for production bundles GCC seems to remove `new` from `new Error()` which broke our proxy. * Build production version of react-noop-renderer This lets us test more bundles. * Switch to blacklist (exclude .private.js tests) * Rename tests that are currently broken against bundles to *-test.internal.js Some of these are using private APIs. Some have other issues. * Add bundle tests to CI * Split private and public ReactJSXElementValidator tests * Remove internal deps from ReactServerRendering-test and make it public * Only run tests directly in __tests__ This lets us share code between test files by placing them in __tests__/utils. * Remove ExecutionEnvironment dependency from DOMServerIntegrationTest It's not necessary since Stack. * Split up ReactDOMServerIntegration into test suite and utilities This enables us to further split it down. Good both for parallelization and extracting public parts. * Split Fragment tests from other DOMServerIntegration tests This enables them to opt other DOMServerIntegration tests into bundle testing. * Split ReactDOMServerIntegration into different test files It was way too slow to run all these in sequence. * Don't reset the cache twice in DOMServerIntegration tests We used to do this to simulate testing separate bundles. But now we actually *do* test bundles. So there is no need for this, as it makes tests slower. * Rename test-bundles* commands to test-build* Also add test-prod-build as alias for test-build-prod because I keep messing them up. * Use regenerator polyfill for react-noop This fixes other issues and finally lets us run ReactNoop tests against a prod bundle. * Run most Incremental tests against bundles Now that GCC generator issue is fixed, we can do this. I split ErrorLogging test separately because it does mocking. Other error handling tests don't need it. * Update sizes * Fix ReactMount test * Enable ReactDOMComponent test * Fix a warning issue uncovered by flat bundle testing With flat bundles, we couldn't produce a good warning for <div onclick={}> on SSR because it doesn't use the event system. However the issue was not visible in normal Jest runs because the event plugins have been injected by the time the test ran. To solve this, I am explicitly passing whether event system is available as an argument to the hook. This makes the behavior consistent between source and bundle tests. Then I change the tests to document the actual logic and _attempt_ to show a nice message (e.g. we know for sure `onclick` is a bad event but we don't know the right name for it on the server so we just say a generic message about camelCase naming convention).
2017-11-24 01:44:58 +08:00
lowerCasedName,
)
? possibleRegistrationNames[lowerCasedName]
: null;
if (registrationName != null) {
warning(
false,
'Invalid event handler property `%s`. Did you mean `%s`?',
Run 90% of tests on compiled bundles (both development and production) (#11633) * Extract Jest config into a separate file * Refactor Jest scripts directory structure Introduces a more consistent naming scheme. * Add yarn test-bundles and yarn test-prod-bundles Only files ending with -test.public.js are opted in (so far we don't have any). * Fix error decoding for production bundles GCC seems to remove `new` from `new Error()` which broke our proxy. * Build production version of react-noop-renderer This lets us test more bundles. * Switch to blacklist (exclude .private.js tests) * Rename tests that are currently broken against bundles to *-test.internal.js Some of these are using private APIs. Some have other issues. * Add bundle tests to CI * Split private and public ReactJSXElementValidator tests * Remove internal deps from ReactServerRendering-test and make it public * Only run tests directly in __tests__ This lets us share code between test files by placing them in __tests__/utils. * Remove ExecutionEnvironment dependency from DOMServerIntegrationTest It's not necessary since Stack. * Split up ReactDOMServerIntegration into test suite and utilities This enables us to further split it down. Good both for parallelization and extracting public parts. * Split Fragment tests from other DOMServerIntegration tests This enables them to opt other DOMServerIntegration tests into bundle testing. * Split ReactDOMServerIntegration into different test files It was way too slow to run all these in sequence. * Don't reset the cache twice in DOMServerIntegration tests We used to do this to simulate testing separate bundles. But now we actually *do* test bundles. So there is no need for this, as it makes tests slower. * Rename test-bundles* commands to test-build* Also add test-prod-build as alias for test-build-prod because I keep messing them up. * Use regenerator polyfill for react-noop This fixes other issues and finally lets us run ReactNoop tests against a prod bundle. * Run most Incremental tests against bundles Now that GCC generator issue is fixed, we can do this. I split ErrorLogging test separately because it does mocking. Other error handling tests don't need it. * Update sizes * Fix ReactMount test * Enable ReactDOMComponent test * Fix a warning issue uncovered by flat bundle testing With flat bundles, we couldn't produce a good warning for <div onclick={}> on SSR because it doesn't use the event system. However the issue was not visible in normal Jest runs because the event plugins have been injected by the time the test ran. To solve this, I am explicitly passing whether event system is available as an argument to the hook. This makes the behavior consistent between source and bundle tests. Then I change the tests to document the actual logic and _attempt_ to show a nice message (e.g. we know for sure `onclick` is a bad event but we don't know the right name for it on the server so we just say a generic message about camelCase naming convention).
2017-11-24 01:44:58 +08:00
name,
registrationName,
);
warnedProperties[name] = true;
return true;
}
if (EVENT_NAME_REGEX.test(name)) {
warning(
false,
'Unknown event handler property `%s`. It will be ignored.',
Run 90% of tests on compiled bundles (both development and production) (#11633) * Extract Jest config into a separate file * Refactor Jest scripts directory structure Introduces a more consistent naming scheme. * Add yarn test-bundles and yarn test-prod-bundles Only files ending with -test.public.js are opted in (so far we don't have any). * Fix error decoding for production bundles GCC seems to remove `new` from `new Error()` which broke our proxy. * Build production version of react-noop-renderer This lets us test more bundles. * Switch to blacklist (exclude .private.js tests) * Rename tests that are currently broken against bundles to *-test.internal.js Some of these are using private APIs. Some have other issues. * Add bundle tests to CI * Split private and public ReactJSXElementValidator tests * Remove internal deps from ReactServerRendering-test and make it public * Only run tests directly in __tests__ This lets us share code between test files by placing them in __tests__/utils. * Remove ExecutionEnvironment dependency from DOMServerIntegrationTest It's not necessary since Stack. * Split up ReactDOMServerIntegration into test suite and utilities This enables us to further split it down. Good both for parallelization and extracting public parts. * Split Fragment tests from other DOMServerIntegration tests This enables them to opt other DOMServerIntegration tests into bundle testing. * Split ReactDOMServerIntegration into different test files It was way too slow to run all these in sequence. * Don't reset the cache twice in DOMServerIntegration tests We used to do this to simulate testing separate bundles. But now we actually *do* test bundles. So there is no need for this, as it makes tests slower. * Rename test-bundles* commands to test-build* Also add test-prod-build as alias for test-build-prod because I keep messing them up. * Use regenerator polyfill for react-noop This fixes other issues and finally lets us run ReactNoop tests against a prod bundle. * Run most Incremental tests against bundles Now that GCC generator issue is fixed, we can do this. I split ErrorLogging test separately because it does mocking. Other error handling tests don't need it. * Update sizes * Fix ReactMount test * Enable ReactDOMComponent test * Fix a warning issue uncovered by flat bundle testing With flat bundles, we couldn't produce a good warning for <div onclick={}> on SSR because it doesn't use the event system. However the issue was not visible in normal Jest runs because the event plugins have been injected by the time the test ran. To solve this, I am explicitly passing whether event system is available as an argument to the hook. This makes the behavior consistent between source and bundle tests. Then I change the tests to document the actual logic and _attempt_ to show a nice message (e.g. we know for sure `onclick` is a bad event but we don't know the right name for it on the server so we just say a generic message about camelCase naming convention).
2017-11-24 01:44:58 +08:00
name,
);
warnedProperties[name] = true;
return true;
}
} else if (EVENT_NAME_REGEX.test(name)) {
// If no event plugins have been injected, we are in a server environment.
// So we can't tell if the event name is correct for sure, but we can filter
// out known bad ones like `onclick`. We can't suggest a specific replacement though.
if (INVALID_EVENT_NAME_REGEX.test(name)) {
warning(
false,
'Invalid event handler property `%s`. ' +
'React events use the camelCase naming convention, for example `onClick`.',
Run 90% of tests on compiled bundles (both development and production) (#11633) * Extract Jest config into a separate file * Refactor Jest scripts directory structure Introduces a more consistent naming scheme. * Add yarn test-bundles and yarn test-prod-bundles Only files ending with -test.public.js are opted in (so far we don't have any). * Fix error decoding for production bundles GCC seems to remove `new` from `new Error()` which broke our proxy. * Build production version of react-noop-renderer This lets us test more bundles. * Switch to blacklist (exclude .private.js tests) * Rename tests that are currently broken against bundles to *-test.internal.js Some of these are using private APIs. Some have other issues. * Add bundle tests to CI * Split private and public ReactJSXElementValidator tests * Remove internal deps from ReactServerRendering-test and make it public * Only run tests directly in __tests__ This lets us share code between test files by placing them in __tests__/utils. * Remove ExecutionEnvironment dependency from DOMServerIntegrationTest It's not necessary since Stack. * Split up ReactDOMServerIntegration into test suite and utilities This enables us to further split it down. Good both for parallelization and extracting public parts. * Split Fragment tests from other DOMServerIntegration tests This enables them to opt other DOMServerIntegration tests into bundle testing. * Split ReactDOMServerIntegration into different test files It was way too slow to run all these in sequence. * Don't reset the cache twice in DOMServerIntegration tests We used to do this to simulate testing separate bundles. But now we actually *do* test bundles. So there is no need for this, as it makes tests slower. * Rename test-bundles* commands to test-build* Also add test-prod-build as alias for test-build-prod because I keep messing them up. * Use regenerator polyfill for react-noop This fixes other issues and finally lets us run ReactNoop tests against a prod bundle. * Run most Incremental tests against bundles Now that GCC generator issue is fixed, we can do this. I split ErrorLogging test separately because it does mocking. Other error handling tests don't need it. * Update sizes * Fix ReactMount test * Enable ReactDOMComponent test * Fix a warning issue uncovered by flat bundle testing With flat bundles, we couldn't produce a good warning for <div onclick={}> on SSR because it doesn't use the event system. However the issue was not visible in normal Jest runs because the event plugins have been injected by the time the test ran. To solve this, I am explicitly passing whether event system is available as an argument to the hook. This makes the behavior consistent between source and bundle tests. Then I change the tests to document the actual logic and _attempt_ to show a nice message (e.g. we know for sure `onclick` is a bad event but we don't know the right name for it on the server so we just say a generic message about camelCase naming convention).
2017-11-24 01:44:58 +08:00
name,
);
}
Changes to attribute whitelist logic (#10564) * Remove HTMLPropertyConfig entries for non-boolean values When we originally removed attributes from the whitelist, we assumed a few attributes were string booleans, but they are not: Autocomplete ("on", "off") https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/Attributes.html#autocomplete Autocapitalize ("none", "sentence", "words", ...) https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/Attributes.html#autocapitalize Autocorrect ("on", "off") https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/Attributes.html#autocorrect Autosave (string) https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/Attributes.html#autosave * Only HAS_BOOLEAN_VALUE attribute flag can assign booleans * Use a non-boolean attribute in object assignment tests * Add HAS_STRING_BOOLEAN_VALUE attribute flag * Fix boolean tests, add boolean warning. * Reserved props should allow booleans * Remove outdated comments * Style tweaks * Don't treat dashed SVG tags as custom elements * SVG elements like font-face are not custom attributes - Adds exceptions to isCustomAttribute for dashed SVG elements - Use consistent custom element check across all modules * Move namespace check to isCustomAttribute. Add caveat for stack. * Remove unused namespace variable assignment * Fix the DEV-only whitelist * Don't read property twice * Ignore and warn about non-string `is` attribute * Blacklist "aria" and "data" attributes * Don't pass unknown on* attributes through * Remove dead code * Avoid accessing namespace when possible * Drop .only in ReactDOMComponent-test * Make isCustomComponent logic more solid * Do attribute name check earlier * Fix fbjs import * Revert unintentional edit * Re-allow "data" attribute We intentionally allowed it. * Use stricter check when attaching events * Pass SVG boolean attributes with correct casing * Fix the test * Undo the SVG dashed-name fix Per conversation with @sebmarkbage we decided that the fix is too complicated, and it's unfortunate it depends on the DOM element. It's only relevant for super rare tags that aren't even working consistently across browsers so we'll leave it unfixed for now. * Prettier * Fix lint * Fix flow * Pass "aria" through but still warn * Remove special cases for onfocusin, onfocusout They're covered by event handler code now. * Add a more specific warning for unknown events * Pass badly cased React attributes through with warning
2017-08-31 09:28:55 +08:00
warnedProperties[name] = true;
return true;
}
Custom Attributes Scenario 2: Write badly cased attributes. Remove most of whitelist. (#10385) * Allow custom attributes. Add flag to toggle custom attribute behavior * Update custom attribute logic - Only allow string attributes - Remove custom attribute feature flag - Add additional tests for data, aria, and custom attributes * Allow numbers and booleans custom attributes. Cut isCustomAttribute * Cover objects with custom attributes in warning test * Rename DOMProperty.isWriteable to shouldSetAttribute * Rework conditions in shouldSetProperty to avoid edge cases * Update unknown property warning to include custom attribute information * Remove ref and key from reserved props * Ensure SSR test coverage for DOMProperty injections * Add ajaxify attribute for internal FB support * Ajaxify is a stringifiable object attribute * Remove non-case sensitive standard attributes. Make ARIA hook dev only. * Update test name for custom attributes on custom elements * Remove SSR custom injection test * Remove case sensitive props * Remove onAfterResetModules hooks in SSR render tests * Add back a few attributes and explain why they are needed * Remove possibleStandardNames from DOMProperty.js * Fix typo in HTMLPropertyConfig comment * Remove duplicative comment * Add back loop boolean property * Do not allow assignment of attributes that are aliased * Update custom attribute test to check value, not just presence * Address case where class is assigned as an attribute on custom elements. Improve SSR tests * Cover cases where className and for are given to custom elements * Remove unnecessary spys on console.error. Reduce extra space in tests * Cover cased custom attributes in SSR tests * Custom attributes are case sensitive * Allow uppercase letters in custom attributes. Address associated edge cases * Allow improperly cased aliased attributes. Add additional tests * Handle special properties like onFocusOut * Add some comments to document where casing matters. Remove DOMPropertyNames * Fix spelling mistake in ajaxify HTML property comment * Make ARIA enforcement dev-only * Remove alias test that covers multiple aliases for one property * Fix typo in comment * Build SVG aliases dynamically * Remove unused DOMPropertyNames reference * Do not translate bad casings of aliased attributes - classname writes to the DOM as classname - class does not write to the DOM - cLASS does not write to the DOM - arabic-form does not write to the DOM * Revise the way custom booleans are treated - Custom attributes can not have boolean values unless they are aria or data attributes - Attributes with boolean values have been added back to the whitelist - Warnings now exclude booleans from supported types - Associated test coverage * Add developer warnings for NaN and ARIA hooks * Use string comparison instead of regex to check for data and aria attributes. * Warn about unsupported properties without case sensitivity * Remove attributes that are updated to invalid values * Support object property values with toString methods. Allow boolean props to coerce objects * Add back ajaxify test * Address bad references in ReactDOMComponent-test. Format. * Revert changes to the docs We'll update them separately * Allow all objects and pass incorrect aliases
2017-08-16 00:00:45 +08:00
// Let the ARIA attribute hook validate ARIA attributes
if (rARIA.test(name) || rARIACamel.test(name)) {
Custom Attributes Scenario 2: Write badly cased attributes. Remove most of whitelist. (#10385) * Allow custom attributes. Add flag to toggle custom attribute behavior * Update custom attribute logic - Only allow string attributes - Remove custom attribute feature flag - Add additional tests for data, aria, and custom attributes * Allow numbers and booleans custom attributes. Cut isCustomAttribute * Cover objects with custom attributes in warning test * Rename DOMProperty.isWriteable to shouldSetAttribute * Rework conditions in shouldSetProperty to avoid edge cases * Update unknown property warning to include custom attribute information * Remove ref and key from reserved props * Ensure SSR test coverage for DOMProperty injections * Add ajaxify attribute for internal FB support * Ajaxify is a stringifiable object attribute * Remove non-case sensitive standard attributes. Make ARIA hook dev only. * Update test name for custom attributes on custom elements * Remove SSR custom injection test * Remove case sensitive props * Remove onAfterResetModules hooks in SSR render tests * Add back a few attributes and explain why they are needed * Remove possibleStandardNames from DOMProperty.js * Fix typo in HTMLPropertyConfig comment * Remove duplicative comment * Add back loop boolean property * Do not allow assignment of attributes that are aliased * Update custom attribute test to check value, not just presence * Address case where class is assigned as an attribute on custom elements. Improve SSR tests * Cover cases where className and for are given to custom elements * Remove unnecessary spys on console.error. Reduce extra space in tests * Cover cased custom attributes in SSR tests * Custom attributes are case sensitive * Allow uppercase letters in custom attributes. Address associated edge cases * Allow improperly cased aliased attributes. Add additional tests * Handle special properties like onFocusOut * Add some comments to document where casing matters. Remove DOMPropertyNames * Fix spelling mistake in ajaxify HTML property comment * Make ARIA enforcement dev-only * Remove alias test that covers multiple aliases for one property * Fix typo in comment * Build SVG aliases dynamically * Remove unused DOMPropertyNames reference * Do not translate bad casings of aliased attributes - classname writes to the DOM as classname - class does not write to the DOM - cLASS does not write to the DOM - arabic-form does not write to the DOM * Revise the way custom booleans are treated - Custom attributes can not have boolean values unless they are aria or data attributes - Attributes with boolean values have been added back to the whitelist - Warnings now exclude booleans from supported types - Associated test coverage * Add developer warnings for NaN and ARIA hooks * Use string comparison instead of regex to check for data and aria attributes. * Warn about unsupported properties without case sensitivity * Remove attributes that are updated to invalid values * Support object property values with toString methods. Allow boolean props to coerce objects * Add back ajaxify test * Address bad references in ReactDOMComponent-test. Format. * Revert changes to the docs We'll update them separately * Allow all objects and pass incorrect aliases
2017-08-16 00:00:45 +08:00
return true;
}
if (lowerCasedName === 'innerhtml') {
warning(
false,
Custom Attributes Scenario 2: Write badly cased attributes. Remove most of whitelist. (#10385) * Allow custom attributes. Add flag to toggle custom attribute behavior * Update custom attribute logic - Only allow string attributes - Remove custom attribute feature flag - Add additional tests for data, aria, and custom attributes * Allow numbers and booleans custom attributes. Cut isCustomAttribute * Cover objects with custom attributes in warning test * Rename DOMProperty.isWriteable to shouldSetAttribute * Rework conditions in shouldSetProperty to avoid edge cases * Update unknown property warning to include custom attribute information * Remove ref and key from reserved props * Ensure SSR test coverage for DOMProperty injections * Add ajaxify attribute for internal FB support * Ajaxify is a stringifiable object attribute * Remove non-case sensitive standard attributes. Make ARIA hook dev only. * Update test name for custom attributes on custom elements * Remove SSR custom injection test * Remove case sensitive props * Remove onAfterResetModules hooks in SSR render tests * Add back a few attributes and explain why they are needed * Remove possibleStandardNames from DOMProperty.js * Fix typo in HTMLPropertyConfig comment * Remove duplicative comment * Add back loop boolean property * Do not allow assignment of attributes that are aliased * Update custom attribute test to check value, not just presence * Address case where class is assigned as an attribute on custom elements. Improve SSR tests * Cover cases where className and for are given to custom elements * Remove unnecessary spys on console.error. Reduce extra space in tests * Cover cased custom attributes in SSR tests * Custom attributes are case sensitive * Allow uppercase letters in custom attributes. Address associated edge cases * Allow improperly cased aliased attributes. Add additional tests * Handle special properties like onFocusOut * Add some comments to document where casing matters. Remove DOMPropertyNames * Fix spelling mistake in ajaxify HTML property comment * Make ARIA enforcement dev-only * Remove alias test that covers multiple aliases for one property * Fix typo in comment * Build SVG aliases dynamically * Remove unused DOMPropertyNames reference * Do not translate bad casings of aliased attributes - classname writes to the DOM as classname - class does not write to the DOM - cLASS does not write to the DOM - arabic-form does not write to the DOM * Revise the way custom booleans are treated - Custom attributes can not have boolean values unless they are aria or data attributes - Attributes with boolean values have been added back to the whitelist - Warnings now exclude booleans from supported types - Associated test coverage * Add developer warnings for NaN and ARIA hooks * Use string comparison instead of regex to check for data and aria attributes. * Warn about unsupported properties without case sensitivity * Remove attributes that are updated to invalid values * Support object property values with toString methods. Allow boolean props to coerce objects * Add back ajaxify test * Address bad references in ReactDOMComponent-test. Format. * Revert changes to the docs We'll update them separately * Allow all objects and pass incorrect aliases
2017-08-16 00:00:45 +08:00
'Directly setting property `innerHTML` is not permitted. ' +
'For more information, lookup documentation on `dangerouslySetInnerHTML`.',
);
warnedProperties[name] = true;
return true;
}
Changes to attribute whitelist logic (#10564) * Remove HTMLPropertyConfig entries for non-boolean values When we originally removed attributes from the whitelist, we assumed a few attributes were string booleans, but they are not: Autocomplete ("on", "off") https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/Attributes.html#autocomplete Autocapitalize ("none", "sentence", "words", ...) https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/Attributes.html#autocapitalize Autocorrect ("on", "off") https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/Attributes.html#autocorrect Autosave (string) https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/Attributes.html#autosave * Only HAS_BOOLEAN_VALUE attribute flag can assign booleans * Use a non-boolean attribute in object assignment tests * Add HAS_STRING_BOOLEAN_VALUE attribute flag * Fix boolean tests, add boolean warning. * Reserved props should allow booleans * Remove outdated comments * Style tweaks * Don't treat dashed SVG tags as custom elements * SVG elements like font-face are not custom attributes - Adds exceptions to isCustomAttribute for dashed SVG elements - Use consistent custom element check across all modules * Move namespace check to isCustomAttribute. Add caveat for stack. * Remove unused namespace variable assignment * Fix the DEV-only whitelist * Don't read property twice * Ignore and warn about non-string `is` attribute * Blacklist "aria" and "data" attributes * Don't pass unknown on* attributes through * Remove dead code * Avoid accessing namespace when possible * Drop .only in ReactDOMComponent-test * Make isCustomComponent logic more solid * Do attribute name check earlier * Fix fbjs import * Revert unintentional edit * Re-allow "data" attribute We intentionally allowed it. * Use stricter check when attaching events * Pass SVG boolean attributes with correct casing * Fix the test * Undo the SVG dashed-name fix Per conversation with @sebmarkbage we decided that the fix is too complicated, and it's unfortunate it depends on the DOM element. It's only relevant for super rare tags that aren't even working consistently across browsers so we'll leave it unfixed for now. * Prettier * Fix lint * Fix flow * Pass "aria" through but still warn * Remove special cases for onfocusin, onfocusout They're covered by event handler code now. * Add a more specific warning for unknown events * Pass badly cased React attributes through with warning
2017-08-31 09:28:55 +08:00
if (lowerCasedName === 'aria') {
warning(
Changes to attribute whitelist logic (#10564) * Remove HTMLPropertyConfig entries for non-boolean values When we originally removed attributes from the whitelist, we assumed a few attributes were string booleans, but they are not: Autocomplete ("on", "off") https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/Attributes.html#autocomplete Autocapitalize ("none", "sentence", "words", ...) https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/Attributes.html#autocapitalize Autocorrect ("on", "off") https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/Attributes.html#autocorrect Autosave (string) https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/Attributes.html#autosave * Only HAS_BOOLEAN_VALUE attribute flag can assign booleans * Use a non-boolean attribute in object assignment tests * Add HAS_STRING_BOOLEAN_VALUE attribute flag * Fix boolean tests, add boolean warning. * Reserved props should allow booleans * Remove outdated comments * Style tweaks * Don't treat dashed SVG tags as custom elements * SVG elements like font-face are not custom attributes - Adds exceptions to isCustomAttribute for dashed SVG elements - Use consistent custom element check across all modules * Move namespace check to isCustomAttribute. Add caveat for stack. * Remove unused namespace variable assignment * Fix the DEV-only whitelist * Don't read property twice * Ignore and warn about non-string `is` attribute * Blacklist "aria" and "data" attributes * Don't pass unknown on* attributes through * Remove dead code * Avoid accessing namespace when possible * Drop .only in ReactDOMComponent-test * Make isCustomComponent logic more solid * Do attribute name check earlier * Fix fbjs import * Revert unintentional edit * Re-allow "data" attribute We intentionally allowed it. * Use stricter check when attaching events * Pass SVG boolean attributes with correct casing * Fix the test * Undo the SVG dashed-name fix Per conversation with @sebmarkbage we decided that the fix is too complicated, and it's unfortunate it depends on the DOM element. It's only relevant for super rare tags that aren't even working consistently across browsers so we'll leave it unfixed for now. * Prettier * Fix lint * Fix flow * Pass "aria" through but still warn * Remove special cases for onfocusin, onfocusout They're covered by event handler code now. * Add a more specific warning for unknown events * Pass badly cased React attributes through with warning
2017-08-31 09:28:55 +08:00
false,
'The `aria` attribute is reserved for future use in React. ' +
'Pass individual `aria-` attributes instead.',
);
warnedProperties[name] = true;
return true;
}
if (
lowerCasedName === 'is' &&
value !== null &&
value !== undefined &&
typeof value !== 'string'
) {
warning(
false,
'Received a `%s` for a string attribute `is`. If this is expected, cast ' +
'the value to a string.',
Changes to attribute whitelist logic (#10564) * Remove HTMLPropertyConfig entries for non-boolean values When we originally removed attributes from the whitelist, we assumed a few attributes were string booleans, but they are not: Autocomplete ("on", "off") https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/Attributes.html#autocomplete Autocapitalize ("none", "sentence", "words", ...) https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/Attributes.html#autocapitalize Autocorrect ("on", "off") https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/Attributes.html#autocorrect Autosave (string) https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/Attributes.html#autosave * Only HAS_BOOLEAN_VALUE attribute flag can assign booleans * Use a non-boolean attribute in object assignment tests * Add HAS_STRING_BOOLEAN_VALUE attribute flag * Fix boolean tests, add boolean warning. * Reserved props should allow booleans * Remove outdated comments * Style tweaks * Don't treat dashed SVG tags as custom elements * SVG elements like font-face are not custom attributes - Adds exceptions to isCustomAttribute for dashed SVG elements - Use consistent custom element check across all modules * Move namespace check to isCustomAttribute. Add caveat for stack. * Remove unused namespace variable assignment * Fix the DEV-only whitelist * Don't read property twice * Ignore and warn about non-string `is` attribute * Blacklist "aria" and "data" attributes * Don't pass unknown on* attributes through * Remove dead code * Avoid accessing namespace when possible * Drop .only in ReactDOMComponent-test * Make isCustomComponent logic more solid * Do attribute name check earlier * Fix fbjs import * Revert unintentional edit * Re-allow "data" attribute We intentionally allowed it. * Use stricter check when attaching events * Pass SVG boolean attributes with correct casing * Fix the test * Undo the SVG dashed-name fix Per conversation with @sebmarkbage we decided that the fix is too complicated, and it's unfortunate it depends on the DOM element. It's only relevant for super rare tags that aren't even working consistently across browsers so we'll leave it unfixed for now. * Prettier * Fix lint * Fix flow * Pass "aria" through but still warn * Remove special cases for onfocusin, onfocusout They're covered by event handler code now. * Add a more specific warning for unknown events * Pass badly cased React attributes through with warning
2017-08-31 09:28:55 +08:00
typeof value,
);
warnedProperties[name] = true;
return true;
}
Custom Attributes Scenario 2: Write badly cased attributes. Remove most of whitelist. (#10385) * Allow custom attributes. Add flag to toggle custom attribute behavior * Update custom attribute logic - Only allow string attributes - Remove custom attribute feature flag - Add additional tests for data, aria, and custom attributes * Allow numbers and booleans custom attributes. Cut isCustomAttribute * Cover objects with custom attributes in warning test * Rename DOMProperty.isWriteable to shouldSetAttribute * Rework conditions in shouldSetProperty to avoid edge cases * Update unknown property warning to include custom attribute information * Remove ref and key from reserved props * Ensure SSR test coverage for DOMProperty injections * Add ajaxify attribute for internal FB support * Ajaxify is a stringifiable object attribute * Remove non-case sensitive standard attributes. Make ARIA hook dev only. * Update test name for custom attributes on custom elements * Remove SSR custom injection test * Remove case sensitive props * Remove onAfterResetModules hooks in SSR render tests * Add back a few attributes and explain why they are needed * Remove possibleStandardNames from DOMProperty.js * Fix typo in HTMLPropertyConfig comment * Remove duplicative comment * Add back loop boolean property * Do not allow assignment of attributes that are aliased * Update custom attribute test to check value, not just presence * Address case where class is assigned as an attribute on custom elements. Improve SSR tests * Cover cases where className and for are given to custom elements * Remove unnecessary spys on console.error. Reduce extra space in tests * Cover cased custom attributes in SSR tests * Custom attributes are case sensitive * Allow uppercase letters in custom attributes. Address associated edge cases * Allow improperly cased aliased attributes. Add additional tests * Handle special properties like onFocusOut * Add some comments to document where casing matters. Remove DOMPropertyNames * Fix spelling mistake in ajaxify HTML property comment * Make ARIA enforcement dev-only * Remove alias test that covers multiple aliases for one property * Fix typo in comment * Build SVG aliases dynamically * Remove unused DOMPropertyNames reference * Do not translate bad casings of aliased attributes - classname writes to the DOM as classname - class does not write to the DOM - cLASS does not write to the DOM - arabic-form does not write to the DOM * Revise the way custom booleans are treated - Custom attributes can not have boolean values unless they are aria or data attributes - Attributes with boolean values have been added back to the whitelist - Warnings now exclude booleans from supported types - Associated test coverage * Add developer warnings for NaN and ARIA hooks * Use string comparison instead of regex to check for data and aria attributes. * Warn about unsupported properties without case sensitivity * Remove attributes that are updated to invalid values * Support object property values with toString methods. Allow boolean props to coerce objects * Add back ajaxify test * Address bad references in ReactDOMComponent-test. Format. * Revert changes to the docs We'll update them separately * Allow all objects and pass incorrect aliases
2017-08-16 00:00:45 +08:00
if (typeof value === 'number' && isNaN(value)) {
warning(
false,
'Received NaN for the `%s` attribute. If this is expected, cast ' +
'the value to a string.',
name,
);
Custom Attributes Scenario 2: Write badly cased attributes. Remove most of whitelist. (#10385) * Allow custom attributes. Add flag to toggle custom attribute behavior * Update custom attribute logic - Only allow string attributes - Remove custom attribute feature flag - Add additional tests for data, aria, and custom attributes * Allow numbers and booleans custom attributes. Cut isCustomAttribute * Cover objects with custom attributes in warning test * Rename DOMProperty.isWriteable to shouldSetAttribute * Rework conditions in shouldSetProperty to avoid edge cases * Update unknown property warning to include custom attribute information * Remove ref and key from reserved props * Ensure SSR test coverage for DOMProperty injections * Add ajaxify attribute for internal FB support * Ajaxify is a stringifiable object attribute * Remove non-case sensitive standard attributes. Make ARIA hook dev only. * Update test name for custom attributes on custom elements * Remove SSR custom injection test * Remove case sensitive props * Remove onAfterResetModules hooks in SSR render tests * Add back a few attributes and explain why they are needed * Remove possibleStandardNames from DOMProperty.js * Fix typo in HTMLPropertyConfig comment * Remove duplicative comment * Add back loop boolean property * Do not allow assignment of attributes that are aliased * Update custom attribute test to check value, not just presence * Address case where class is assigned as an attribute on custom elements. Improve SSR tests * Cover cases where className and for are given to custom elements * Remove unnecessary spys on console.error. Reduce extra space in tests * Cover cased custom attributes in SSR tests * Custom attributes are case sensitive * Allow uppercase letters in custom attributes. Address associated edge cases * Allow improperly cased aliased attributes. Add additional tests * Handle special properties like onFocusOut * Add some comments to document where casing matters. Remove DOMPropertyNames * Fix spelling mistake in ajaxify HTML property comment * Make ARIA enforcement dev-only * Remove alias test that covers multiple aliases for one property * Fix typo in comment * Build SVG aliases dynamically * Remove unused DOMPropertyNames reference * Do not translate bad casings of aliased attributes - classname writes to the DOM as classname - class does not write to the DOM - cLASS does not write to the DOM - arabic-form does not write to the DOM * Revise the way custom booleans are treated - Custom attributes can not have boolean values unless they are aria or data attributes - Attributes with boolean values have been added back to the whitelist - Warnings now exclude booleans from supported types - Associated test coverage * Add developer warnings for NaN and ARIA hooks * Use string comparison instead of regex to check for data and aria attributes. * Warn about unsupported properties without case sensitivity * Remove attributes that are updated to invalid values * Support object property values with toString methods. Allow boolean props to coerce objects * Add back ajaxify test * Address bad references in ReactDOMComponent-test. Format. * Revert changes to the docs We'll update them separately * Allow all objects and pass incorrect aliases
2017-08-16 00:00:45 +08:00
warnedProperties[name] = true;
return true;
}
Refactor DOM attribute code (take two) (#11815) * Harden tests around init/addition/update/removal of aliased attributes I noticed some patterns weren't being tested. * Call setValueForProperty() for null and undefined The branching before the call is unnecessary because setValueForProperty() already has an internal branch that delegates to deleteValueForProperty() for null and undefined through the shouldIgnoreValue() check. The goal is to start unifying these methods because their separation doesn't reflect the current behavior (e.g. for unknown properties) anymore, and obscures what actually happens with different inputs. * Inline deleteValueForProperty() into setValueForProperty() Now we don't read propertyInfo twice in this case. I also dropped a few early returns. I added them a while ago when we had Stack-only tracking of DOM operations, and some operations were being counted twice because of how this code is structured. This isn't a problem anymore (both because we don't track operations, and because I've just inlined this method call). * Inline deleteValueForAttribute() into setValueForAttribute() The special cases for null and undefined already exist in setValueForAttribute(). * Delete some dead code * Make setValueForAttribute() a branch of setValueForProperty() Their naming is pretty confusing by now. For example setValueForProperty() calls setValueForAttribute() when shouldSetAttribute() is false (!). I want to refactor (as in, inline and then maybe factor it out differently) the relation between them. For now, I'm consolidating the callers to use setValueForProperty(). * Make it more obvious where we skip and when we reset attributes The naming of these methods is still very vague and conflicting in some cases. Will need further work. * Rewrite setValueForProperty() with early exits This makes the flow clearer in my opinion. * Move shouldIgnoreValue() into DOMProperty It was previously duplicated. It's also suspiciously similar in purpose to shouldTreatAttributeValueAsNull() so I want to see if there is a way to unify them. * Use more specific methods for testing validity * Unify shouldTreatAttributeValueAsNull() and shouldIgnoreValue() * Remove shouldSetAttribute() Its naming was confusing and it was used all over the place instead of more specific checks. Now that we only have one call site, we might as well inline and get rid of it. * Remove unnecessary condition * Remove another unnecessary condition * Add Flow coverage * Oops * Fix lint (ESLint complains about Flow suppression) * Fix treatment of Symbol/Function values on boolean attributes They weren't being properly skipped because of the early return. I added tests for this case. * Avoid getPropertyInfo() calls I think this PR looks worse on benchmarks because we have to read propertyInfo in different places. Originally I tried to get rid of propertyInfo, but looks like it's important for performance after all. So now I'm going into the opposite direction, and precompute propertyInfo as early as possible, and then just pass it around. This way we can avoid extra lookups but keep functions nice and modular. * Pass propertyInfo as argument to getValueForProperty() It always exists because this function is only called for known properties. * Make it clearer this branch is boolean-specific I wrote this and then got confused myself. * Memoize whether propertyInfo accepts boolean value Since we run these checks for all booleans, might as well remember it. * Fix a crash when numeric property is given a Symbol * Record attribute table The changes reflect that SSR doesn't crash with symbols anymore (and just warns, consistently with the client). * Refactor attribute initialization Instead of using flags, explicitly group similar attributes/properties. * Optimization: we know built-in attributes are never invalid * Use strict comparison * Rename methods for clarity * Lint nit * Minor tweaks * Document all the different attribute types
2017-12-11 00:58:38 +08:00
const propertyInfo = getPropertyInfo(name);
const isReserved = propertyInfo !== null && propertyInfo.type === RESERVED;
Custom Attributes Scenario 2: Write badly cased attributes. Remove most of whitelist. (#10385) * Allow custom attributes. Add flag to toggle custom attribute behavior * Update custom attribute logic - Only allow string attributes - Remove custom attribute feature flag - Add additional tests for data, aria, and custom attributes * Allow numbers and booleans custom attributes. Cut isCustomAttribute * Cover objects with custom attributes in warning test * Rename DOMProperty.isWriteable to shouldSetAttribute * Rework conditions in shouldSetProperty to avoid edge cases * Update unknown property warning to include custom attribute information * Remove ref and key from reserved props * Ensure SSR test coverage for DOMProperty injections * Add ajaxify attribute for internal FB support * Ajaxify is a stringifiable object attribute * Remove non-case sensitive standard attributes. Make ARIA hook dev only. * Update test name for custom attributes on custom elements * Remove SSR custom injection test * Remove case sensitive props * Remove onAfterResetModules hooks in SSR render tests * Add back a few attributes and explain why they are needed * Remove possibleStandardNames from DOMProperty.js * Fix typo in HTMLPropertyConfig comment * Remove duplicative comment * Add back loop boolean property * Do not allow assignment of attributes that are aliased * Update custom attribute test to check value, not just presence * Address case where class is assigned as an attribute on custom elements. Improve SSR tests * Cover cases where className and for are given to custom elements * Remove unnecessary spys on console.error. Reduce extra space in tests * Cover cased custom attributes in SSR tests * Custom attributes are case sensitive * Allow uppercase letters in custom attributes. Address associated edge cases * Allow improperly cased aliased attributes. Add additional tests * Handle special properties like onFocusOut * Add some comments to document where casing matters. Remove DOMPropertyNames * Fix spelling mistake in ajaxify HTML property comment * Make ARIA enforcement dev-only * Remove alias test that covers multiple aliases for one property * Fix typo in comment * Build SVG aliases dynamically * Remove unused DOMPropertyNames reference * Do not translate bad casings of aliased attributes - classname writes to the DOM as classname - class does not write to the DOM - cLASS does not write to the DOM - arabic-form does not write to the DOM * Revise the way custom booleans are treated - Custom attributes can not have boolean values unless they are aria or data attributes - Attributes with boolean values have been added back to the whitelist - Warnings now exclude booleans from supported types - Associated test coverage * Add developer warnings for NaN and ARIA hooks * Use string comparison instead of regex to check for data and aria attributes. * Warn about unsupported properties without case sensitivity * Remove attributes that are updated to invalid values * Support object property values with toString methods. Allow boolean props to coerce objects * Add back ajaxify test * Address bad references in ReactDOMComponent-test. Format. * Revert changes to the docs We'll update them separately * Allow all objects and pass incorrect aliases
2017-08-16 00:00:45 +08:00
// Known attributes should match the casing specified in the property config.
if (possibleStandardNames.hasOwnProperty(lowerCasedName)) {
const standardName = possibleStandardNames[lowerCasedName];
Custom Attributes Scenario 2: Write badly cased attributes. Remove most of whitelist. (#10385) * Allow custom attributes. Add flag to toggle custom attribute behavior * Update custom attribute logic - Only allow string attributes - Remove custom attribute feature flag - Add additional tests for data, aria, and custom attributes * Allow numbers and booleans custom attributes. Cut isCustomAttribute * Cover objects with custom attributes in warning test * Rename DOMProperty.isWriteable to shouldSetAttribute * Rework conditions in shouldSetProperty to avoid edge cases * Update unknown property warning to include custom attribute information * Remove ref and key from reserved props * Ensure SSR test coverage for DOMProperty injections * Add ajaxify attribute for internal FB support * Ajaxify is a stringifiable object attribute * Remove non-case sensitive standard attributes. Make ARIA hook dev only. * Update test name for custom attributes on custom elements * Remove SSR custom injection test * Remove case sensitive props * Remove onAfterResetModules hooks in SSR render tests * Add back a few attributes and explain why they are needed * Remove possibleStandardNames from DOMProperty.js * Fix typo in HTMLPropertyConfig comment * Remove duplicative comment * Add back loop boolean property * Do not allow assignment of attributes that are aliased * Update custom attribute test to check value, not just presence * Address case where class is assigned as an attribute on custom elements. Improve SSR tests * Cover cases where className and for are given to custom elements * Remove unnecessary spys on console.error. Reduce extra space in tests * Cover cased custom attributes in SSR tests * Custom attributes are case sensitive * Allow uppercase letters in custom attributes. Address associated edge cases * Allow improperly cased aliased attributes. Add additional tests * Handle special properties like onFocusOut * Add some comments to document where casing matters. Remove DOMPropertyNames * Fix spelling mistake in ajaxify HTML property comment * Make ARIA enforcement dev-only * Remove alias test that covers multiple aliases for one property * Fix typo in comment * Build SVG aliases dynamically * Remove unused DOMPropertyNames reference * Do not translate bad casings of aliased attributes - classname writes to the DOM as classname - class does not write to the DOM - cLASS does not write to the DOM - arabic-form does not write to the DOM * Revise the way custom booleans are treated - Custom attributes can not have boolean values unless they are aria or data attributes - Attributes with boolean values have been added back to the whitelist - Warnings now exclude booleans from supported types - Associated test coverage * Add developer warnings for NaN and ARIA hooks * Use string comparison instead of regex to check for data and aria attributes. * Warn about unsupported properties without case sensitivity * Remove attributes that are updated to invalid values * Support object property values with toString methods. Allow boolean props to coerce objects * Add back ajaxify test * Address bad references in ReactDOMComponent-test. Format. * Revert changes to the docs We'll update them separately * Allow all objects and pass incorrect aliases
2017-08-16 00:00:45 +08:00
if (standardName !== name) {
warning(
false,
'Invalid DOM property `%s`. Did you mean `%s`?',
Custom Attributes Scenario 2: Write badly cased attributes. Remove most of whitelist. (#10385) * Allow custom attributes. Add flag to toggle custom attribute behavior * Update custom attribute logic - Only allow string attributes - Remove custom attribute feature flag - Add additional tests for data, aria, and custom attributes * Allow numbers and booleans custom attributes. Cut isCustomAttribute * Cover objects with custom attributes in warning test * Rename DOMProperty.isWriteable to shouldSetAttribute * Rework conditions in shouldSetProperty to avoid edge cases * Update unknown property warning to include custom attribute information * Remove ref and key from reserved props * Ensure SSR test coverage for DOMProperty injections * Add ajaxify attribute for internal FB support * Ajaxify is a stringifiable object attribute * Remove non-case sensitive standard attributes. Make ARIA hook dev only. * Update test name for custom attributes on custom elements * Remove SSR custom injection test * Remove case sensitive props * Remove onAfterResetModules hooks in SSR render tests * Add back a few attributes and explain why they are needed * Remove possibleStandardNames from DOMProperty.js * Fix typo in HTMLPropertyConfig comment * Remove duplicative comment * Add back loop boolean property * Do not allow assignment of attributes that are aliased * Update custom attribute test to check value, not just presence * Address case where class is assigned as an attribute on custom elements. Improve SSR tests * Cover cases where className and for are given to custom elements * Remove unnecessary spys on console.error. Reduce extra space in tests * Cover cased custom attributes in SSR tests * Custom attributes are case sensitive * Allow uppercase letters in custom attributes. Address associated edge cases * Allow improperly cased aliased attributes. Add additional tests * Handle special properties like onFocusOut * Add some comments to document where casing matters. Remove DOMPropertyNames * Fix spelling mistake in ajaxify HTML property comment * Make ARIA enforcement dev-only * Remove alias test that covers multiple aliases for one property * Fix typo in comment * Build SVG aliases dynamically * Remove unused DOMPropertyNames reference * Do not translate bad casings of aliased attributes - classname writes to the DOM as classname - class does not write to the DOM - cLASS does not write to the DOM - arabic-form does not write to the DOM * Revise the way custom booleans are treated - Custom attributes can not have boolean values unless they are aria or data attributes - Attributes with boolean values have been added back to the whitelist - Warnings now exclude booleans from supported types - Associated test coverage * Add developer warnings for NaN and ARIA hooks * Use string comparison instead of regex to check for data and aria attributes. * Warn about unsupported properties without case sensitivity * Remove attributes that are updated to invalid values * Support object property values with toString methods. Allow boolean props to coerce objects * Add back ajaxify test * Address bad references in ReactDOMComponent-test. Format. * Revert changes to the docs We'll update them separately * Allow all objects and pass incorrect aliases
2017-08-16 00:00:45 +08:00
name,
standardName,
);
warnedProperties[name] = true;
return true;
}
} else if (!isReserved && name !== lowerCasedName) {
// Unknown attributes should have lowercase casing since that's how they
// will be cased anyway with server rendering.
warning(
false,
'React does not recognize the `%s` prop on a DOM element. If you ' +
'intentionally want it to appear in the DOM as a custom ' +
'attribute, spell it as lowercase `%s` instead. ' +
'If you accidentally passed it from a parent component, remove ' +
'it from the DOM element.',
name,
lowerCasedName,
);
warnedProperties[name] = true;
return true;
Custom Attributes Scenario 2: Write badly cased attributes. Remove most of whitelist. (#10385) * Allow custom attributes. Add flag to toggle custom attribute behavior * Update custom attribute logic - Only allow string attributes - Remove custom attribute feature flag - Add additional tests for data, aria, and custom attributes * Allow numbers and booleans custom attributes. Cut isCustomAttribute * Cover objects with custom attributes in warning test * Rename DOMProperty.isWriteable to shouldSetAttribute * Rework conditions in shouldSetProperty to avoid edge cases * Update unknown property warning to include custom attribute information * Remove ref and key from reserved props * Ensure SSR test coverage for DOMProperty injections * Add ajaxify attribute for internal FB support * Ajaxify is a stringifiable object attribute * Remove non-case sensitive standard attributes. Make ARIA hook dev only. * Update test name for custom attributes on custom elements * Remove SSR custom injection test * Remove case sensitive props * Remove onAfterResetModules hooks in SSR render tests * Add back a few attributes and explain why they are needed * Remove possibleStandardNames from DOMProperty.js * Fix typo in HTMLPropertyConfig comment * Remove duplicative comment * Add back loop boolean property * Do not allow assignment of attributes that are aliased * Update custom attribute test to check value, not just presence * Address case where class is assigned as an attribute on custom elements. Improve SSR tests * Cover cases where className and for are given to custom elements * Remove unnecessary spys on console.error. Reduce extra space in tests * Cover cased custom attributes in SSR tests * Custom attributes are case sensitive * Allow uppercase letters in custom attributes. Address associated edge cases * Allow improperly cased aliased attributes. Add additional tests * Handle special properties like onFocusOut * Add some comments to document where casing matters. Remove DOMPropertyNames * Fix spelling mistake in ajaxify HTML property comment * Make ARIA enforcement dev-only * Remove alias test that covers multiple aliases for one property * Fix typo in comment * Build SVG aliases dynamically * Remove unused DOMPropertyNames reference * Do not translate bad casings of aliased attributes - classname writes to the DOM as classname - class does not write to the DOM - cLASS does not write to the DOM - arabic-form does not write to the DOM * Revise the way custom booleans are treated - Custom attributes can not have boolean values unless they are aria or data attributes - Attributes with boolean values have been added back to the whitelist - Warnings now exclude booleans from supported types - Associated test coverage * Add developer warnings for NaN and ARIA hooks * Use string comparison instead of regex to check for data and aria attributes. * Warn about unsupported properties without case sensitivity * Remove attributes that are updated to invalid values * Support object property values with toString methods. Allow boolean props to coerce objects * Add back ajaxify test * Address bad references in ReactDOMComponent-test. Format. * Revert changes to the docs We'll update them separately * Allow all objects and pass incorrect aliases
2017-08-16 00:00:45 +08:00
}
if (
typeof value === 'boolean' &&
Refactor DOM attribute code (take two) (#11815) * Harden tests around init/addition/update/removal of aliased attributes I noticed some patterns weren't being tested. * Call setValueForProperty() for null and undefined The branching before the call is unnecessary because setValueForProperty() already has an internal branch that delegates to deleteValueForProperty() for null and undefined through the shouldIgnoreValue() check. The goal is to start unifying these methods because their separation doesn't reflect the current behavior (e.g. for unknown properties) anymore, and obscures what actually happens with different inputs. * Inline deleteValueForProperty() into setValueForProperty() Now we don't read propertyInfo twice in this case. I also dropped a few early returns. I added them a while ago when we had Stack-only tracking of DOM operations, and some operations were being counted twice because of how this code is structured. This isn't a problem anymore (both because we don't track operations, and because I've just inlined this method call). * Inline deleteValueForAttribute() into setValueForAttribute() The special cases for null and undefined already exist in setValueForAttribute(). * Delete some dead code * Make setValueForAttribute() a branch of setValueForProperty() Their naming is pretty confusing by now. For example setValueForProperty() calls setValueForAttribute() when shouldSetAttribute() is false (!). I want to refactor (as in, inline and then maybe factor it out differently) the relation between them. For now, I'm consolidating the callers to use setValueForProperty(). * Make it more obvious where we skip and when we reset attributes The naming of these methods is still very vague and conflicting in some cases. Will need further work. * Rewrite setValueForProperty() with early exits This makes the flow clearer in my opinion. * Move shouldIgnoreValue() into DOMProperty It was previously duplicated. It's also suspiciously similar in purpose to shouldTreatAttributeValueAsNull() so I want to see if there is a way to unify them. * Use more specific methods for testing validity * Unify shouldTreatAttributeValueAsNull() and shouldIgnoreValue() * Remove shouldSetAttribute() Its naming was confusing and it was used all over the place instead of more specific checks. Now that we only have one call site, we might as well inline and get rid of it. * Remove unnecessary condition * Remove another unnecessary condition * Add Flow coverage * Oops * Fix lint (ESLint complains about Flow suppression) * Fix treatment of Symbol/Function values on boolean attributes They weren't being properly skipped because of the early return. I added tests for this case. * Avoid getPropertyInfo() calls I think this PR looks worse on benchmarks because we have to read propertyInfo in different places. Originally I tried to get rid of propertyInfo, but looks like it's important for performance after all. So now I'm going into the opposite direction, and precompute propertyInfo as early as possible, and then just pass it around. This way we can avoid extra lookups but keep functions nice and modular. * Pass propertyInfo as argument to getValueForProperty() It always exists because this function is only called for known properties. * Make it clearer this branch is boolean-specific I wrote this and then got confused myself. * Memoize whether propertyInfo accepts boolean value Since we run these checks for all booleans, might as well remember it. * Fix a crash when numeric property is given a Symbol * Record attribute table The changes reflect that SSR doesn't crash with symbols anymore (and just warns, consistently with the client). * Refactor attribute initialization Instead of using flags, explicitly group similar attributes/properties. * Optimization: we know built-in attributes are never invalid * Use strict comparison * Rename methods for clarity * Lint nit * Minor tweaks * Document all the different attribute types
2017-12-11 00:58:38 +08:00
shouldRemoveAttributeWithWarning(name, value, propertyInfo, false)
) {
if (value) {
warning(
false,
'Received `%s` for a non-boolean attribute `%s`.\n\n' +
'If you want to write it to the DOM, pass a string instead: ' +
'%s="%s" or %s={value.toString()}.',
value,
name,
name,
value,
name,
);
} else {
warning(
false,
'Received `%s` for a non-boolean attribute `%s`.\n\n' +
'If you want to write it to the DOM, pass a string instead: ' +
'%s="%s" or %s={value.toString()}.\n\n' +
'If you used to conditionally omit it with %s={condition && value}, ' +
'pass %s={condition ? value : undefined} instead.',
value,
name,
name,
value,
name,
name,
name,
);
}
Changes to attribute whitelist logic (#10564) * Remove HTMLPropertyConfig entries for non-boolean values When we originally removed attributes from the whitelist, we assumed a few attributes were string booleans, but they are not: Autocomplete ("on", "off") https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/Attributes.html#autocomplete Autocapitalize ("none", "sentence", "words", ...) https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/Attributes.html#autocapitalize Autocorrect ("on", "off") https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/Attributes.html#autocorrect Autosave (string) https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/Attributes.html#autosave * Only HAS_BOOLEAN_VALUE attribute flag can assign booleans * Use a non-boolean attribute in object assignment tests * Add HAS_STRING_BOOLEAN_VALUE attribute flag * Fix boolean tests, add boolean warning. * Reserved props should allow booleans * Remove outdated comments * Style tweaks * Don't treat dashed SVG tags as custom elements * SVG elements like font-face are not custom attributes - Adds exceptions to isCustomAttribute for dashed SVG elements - Use consistent custom element check across all modules * Move namespace check to isCustomAttribute. Add caveat for stack. * Remove unused namespace variable assignment * Fix the DEV-only whitelist * Don't read property twice * Ignore and warn about non-string `is` attribute * Blacklist "aria" and "data" attributes * Don't pass unknown on* attributes through * Remove dead code * Avoid accessing namespace when possible * Drop .only in ReactDOMComponent-test * Make isCustomComponent logic more solid * Do attribute name check earlier * Fix fbjs import * Revert unintentional edit * Re-allow "data" attribute We intentionally allowed it. * Use stricter check when attaching events * Pass SVG boolean attributes with correct casing * Fix the test * Undo the SVG dashed-name fix Per conversation with @sebmarkbage we decided that the fix is too complicated, and it's unfortunate it depends on the DOM element. It's only relevant for super rare tags that aren't even working consistently across browsers so we'll leave it unfixed for now. * Prettier * Fix lint * Fix flow * Pass "aria" through but still warn * Remove special cases for onfocusin, onfocusout They're covered by event handler code now. * Add a more specific warning for unknown events * Pass badly cased React attributes through with warning
2017-08-31 09:28:55 +08:00
warnedProperties[name] = true;
return true;
}
Custom Attributes Scenario 2: Write badly cased attributes. Remove most of whitelist. (#10385) * Allow custom attributes. Add flag to toggle custom attribute behavior * Update custom attribute logic - Only allow string attributes - Remove custom attribute feature flag - Add additional tests for data, aria, and custom attributes * Allow numbers and booleans custom attributes. Cut isCustomAttribute * Cover objects with custom attributes in warning test * Rename DOMProperty.isWriteable to shouldSetAttribute * Rework conditions in shouldSetProperty to avoid edge cases * Update unknown property warning to include custom attribute information * Remove ref and key from reserved props * Ensure SSR test coverage for DOMProperty injections * Add ajaxify attribute for internal FB support * Ajaxify is a stringifiable object attribute * Remove non-case sensitive standard attributes. Make ARIA hook dev only. * Update test name for custom attributes on custom elements * Remove SSR custom injection test * Remove case sensitive props * Remove onAfterResetModules hooks in SSR render tests * Add back a few attributes and explain why they are needed * Remove possibleStandardNames from DOMProperty.js * Fix typo in HTMLPropertyConfig comment * Remove duplicative comment * Add back loop boolean property * Do not allow assignment of attributes that are aliased * Update custom attribute test to check value, not just presence * Address case where class is assigned as an attribute on custom elements. Improve SSR tests * Cover cases where className and for are given to custom elements * Remove unnecessary spys on console.error. Reduce extra space in tests * Cover cased custom attributes in SSR tests * Custom attributes are case sensitive * Allow uppercase letters in custom attributes. Address associated edge cases * Allow improperly cased aliased attributes. Add additional tests * Handle special properties like onFocusOut * Add some comments to document where casing matters. Remove DOMPropertyNames * Fix spelling mistake in ajaxify HTML property comment * Make ARIA enforcement dev-only * Remove alias test that covers multiple aliases for one property * Fix typo in comment * Build SVG aliases dynamically * Remove unused DOMPropertyNames reference * Do not translate bad casings of aliased attributes - classname writes to the DOM as classname - class does not write to the DOM - cLASS does not write to the DOM - arabic-form does not write to the DOM * Revise the way custom booleans are treated - Custom attributes can not have boolean values unless they are aria or data attributes - Attributes with boolean values have been added back to the whitelist - Warnings now exclude booleans from supported types - Associated test coverage * Add developer warnings for NaN and ARIA hooks * Use string comparison instead of regex to check for data and aria attributes. * Warn about unsupported properties without case sensitivity * Remove attributes that are updated to invalid values * Support object property values with toString methods. Allow boolean props to coerce objects * Add back ajaxify test * Address bad references in ReactDOMComponent-test. Format. * Revert changes to the docs We'll update them separately * Allow all objects and pass incorrect aliases
2017-08-16 00:00:45 +08:00
// Now that we've validated casing, do not validate
// data types for reserved props
if (isReserved) {
return true;
Custom Attributes Scenario 2: Write badly cased attributes. Remove most of whitelist. (#10385) * Allow custom attributes. Add flag to toggle custom attribute behavior * Update custom attribute logic - Only allow string attributes - Remove custom attribute feature flag - Add additional tests for data, aria, and custom attributes * Allow numbers and booleans custom attributes. Cut isCustomAttribute * Cover objects with custom attributes in warning test * Rename DOMProperty.isWriteable to shouldSetAttribute * Rework conditions in shouldSetProperty to avoid edge cases * Update unknown property warning to include custom attribute information * Remove ref and key from reserved props * Ensure SSR test coverage for DOMProperty injections * Add ajaxify attribute for internal FB support * Ajaxify is a stringifiable object attribute * Remove non-case sensitive standard attributes. Make ARIA hook dev only. * Update test name for custom attributes on custom elements * Remove SSR custom injection test * Remove case sensitive props * Remove onAfterResetModules hooks in SSR render tests * Add back a few attributes and explain why they are needed * Remove possibleStandardNames from DOMProperty.js * Fix typo in HTMLPropertyConfig comment * Remove duplicative comment * Add back loop boolean property * Do not allow assignment of attributes that are aliased * Update custom attribute test to check value, not just presence * Address case where class is assigned as an attribute on custom elements. Improve SSR tests * Cover cases where className and for are given to custom elements * Remove unnecessary spys on console.error. Reduce extra space in tests * Cover cased custom attributes in SSR tests * Custom attributes are case sensitive * Allow uppercase letters in custom attributes. Address associated edge cases * Allow improperly cased aliased attributes. Add additional tests * Handle special properties like onFocusOut * Add some comments to document where casing matters. Remove DOMPropertyNames * Fix spelling mistake in ajaxify HTML property comment * Make ARIA enforcement dev-only * Remove alias test that covers multiple aliases for one property * Fix typo in comment * Build SVG aliases dynamically * Remove unused DOMPropertyNames reference * Do not translate bad casings of aliased attributes - classname writes to the DOM as classname - class does not write to the DOM - cLASS does not write to the DOM - arabic-form does not write to the DOM * Revise the way custom booleans are treated - Custom attributes can not have boolean values unless they are aria or data attributes - Attributes with boolean values have been added back to the whitelist - Warnings now exclude booleans from supported types - Associated test coverage * Add developer warnings for NaN and ARIA hooks * Use string comparison instead of regex to check for data and aria attributes. * Warn about unsupported properties without case sensitivity * Remove attributes that are updated to invalid values * Support object property values with toString methods. Allow boolean props to coerce objects * Add back ajaxify test * Address bad references in ReactDOMComponent-test. Format. * Revert changes to the docs We'll update them separately * Allow all objects and pass incorrect aliases
2017-08-16 00:00:45 +08:00
}
// Warn when a known attribute is a bad type
Refactor DOM attribute code (take two) (#11815) * Harden tests around init/addition/update/removal of aliased attributes I noticed some patterns weren't being tested. * Call setValueForProperty() for null and undefined The branching before the call is unnecessary because setValueForProperty() already has an internal branch that delegates to deleteValueForProperty() for null and undefined through the shouldIgnoreValue() check. The goal is to start unifying these methods because their separation doesn't reflect the current behavior (e.g. for unknown properties) anymore, and obscures what actually happens with different inputs. * Inline deleteValueForProperty() into setValueForProperty() Now we don't read propertyInfo twice in this case. I also dropped a few early returns. I added them a while ago when we had Stack-only tracking of DOM operations, and some operations were being counted twice because of how this code is structured. This isn't a problem anymore (both because we don't track operations, and because I've just inlined this method call). * Inline deleteValueForAttribute() into setValueForAttribute() The special cases for null and undefined already exist in setValueForAttribute(). * Delete some dead code * Make setValueForAttribute() a branch of setValueForProperty() Their naming is pretty confusing by now. For example setValueForProperty() calls setValueForAttribute() when shouldSetAttribute() is false (!). I want to refactor (as in, inline and then maybe factor it out differently) the relation between them. For now, I'm consolidating the callers to use setValueForProperty(). * Make it more obvious where we skip and when we reset attributes The naming of these methods is still very vague and conflicting in some cases. Will need further work. * Rewrite setValueForProperty() with early exits This makes the flow clearer in my opinion. * Move shouldIgnoreValue() into DOMProperty It was previously duplicated. It's also suspiciously similar in purpose to shouldTreatAttributeValueAsNull() so I want to see if there is a way to unify them. * Use more specific methods for testing validity * Unify shouldTreatAttributeValueAsNull() and shouldIgnoreValue() * Remove shouldSetAttribute() Its naming was confusing and it was used all over the place instead of more specific checks. Now that we only have one call site, we might as well inline and get rid of it. * Remove unnecessary condition * Remove another unnecessary condition * Add Flow coverage * Oops * Fix lint (ESLint complains about Flow suppression) * Fix treatment of Symbol/Function values on boolean attributes They weren't being properly skipped because of the early return. I added tests for this case. * Avoid getPropertyInfo() calls I think this PR looks worse on benchmarks because we have to read propertyInfo in different places. Originally I tried to get rid of propertyInfo, but looks like it's important for performance after all. So now I'm going into the opposite direction, and precompute propertyInfo as early as possible, and then just pass it around. This way we can avoid extra lookups but keep functions nice and modular. * Pass propertyInfo as argument to getValueForProperty() It always exists because this function is only called for known properties. * Make it clearer this branch is boolean-specific I wrote this and then got confused myself. * Memoize whether propertyInfo accepts boolean value Since we run these checks for all booleans, might as well remember it. * Fix a crash when numeric property is given a Symbol * Record attribute table The changes reflect that SSR doesn't crash with symbols anymore (and just warns, consistently with the client). * Refactor attribute initialization Instead of using flags, explicitly group similar attributes/properties. * Optimization: we know built-in attributes are never invalid * Use strict comparison * Rename methods for clarity * Lint nit * Minor tweaks * Document all the different attribute types
2017-12-11 00:58:38 +08:00
if (shouldRemoveAttributeWithWarning(name, value, propertyInfo, false)) {
Custom Attributes Scenario 2: Write badly cased attributes. Remove most of whitelist. (#10385) * Allow custom attributes. Add flag to toggle custom attribute behavior * Update custom attribute logic - Only allow string attributes - Remove custom attribute feature flag - Add additional tests for data, aria, and custom attributes * Allow numbers and booleans custom attributes. Cut isCustomAttribute * Cover objects with custom attributes in warning test * Rename DOMProperty.isWriteable to shouldSetAttribute * Rework conditions in shouldSetProperty to avoid edge cases * Update unknown property warning to include custom attribute information * Remove ref and key from reserved props * Ensure SSR test coverage for DOMProperty injections * Add ajaxify attribute for internal FB support * Ajaxify is a stringifiable object attribute * Remove non-case sensitive standard attributes. Make ARIA hook dev only. * Update test name for custom attributes on custom elements * Remove SSR custom injection test * Remove case sensitive props * Remove onAfterResetModules hooks in SSR render tests * Add back a few attributes and explain why they are needed * Remove possibleStandardNames from DOMProperty.js * Fix typo in HTMLPropertyConfig comment * Remove duplicative comment * Add back loop boolean property * Do not allow assignment of attributes that are aliased * Update custom attribute test to check value, not just presence * Address case where class is assigned as an attribute on custom elements. Improve SSR tests * Cover cases where className and for are given to custom elements * Remove unnecessary spys on console.error. Reduce extra space in tests * Cover cased custom attributes in SSR tests * Custom attributes are case sensitive * Allow uppercase letters in custom attributes. Address associated edge cases * Allow improperly cased aliased attributes. Add additional tests * Handle special properties like onFocusOut * Add some comments to document where casing matters. Remove DOMPropertyNames * Fix spelling mistake in ajaxify HTML property comment * Make ARIA enforcement dev-only * Remove alias test that covers multiple aliases for one property * Fix typo in comment * Build SVG aliases dynamically * Remove unused DOMPropertyNames reference * Do not translate bad casings of aliased attributes - classname writes to the DOM as classname - class does not write to the DOM - cLASS does not write to the DOM - arabic-form does not write to the DOM * Revise the way custom booleans are treated - Custom attributes can not have boolean values unless they are aria or data attributes - Attributes with boolean values have been added back to the whitelist - Warnings now exclude booleans from supported types - Associated test coverage * Add developer warnings for NaN and ARIA hooks * Use string comparison instead of regex to check for data and aria attributes. * Warn about unsupported properties without case sensitivity * Remove attributes that are updated to invalid values * Support object property values with toString methods. Allow boolean props to coerce objects * Add back ajaxify test * Address bad references in ReactDOMComponent-test. Format. * Revert changes to the docs We'll update them separately * Allow all objects and pass incorrect aliases
2017-08-16 00:00:45 +08:00
warnedProperties[name] = true;
return false;
}
Custom Attributes Scenario 2: Write badly cased attributes. Remove most of whitelist. (#10385) * Allow custom attributes. Add flag to toggle custom attribute behavior * Update custom attribute logic - Only allow string attributes - Remove custom attribute feature flag - Add additional tests for data, aria, and custom attributes * Allow numbers and booleans custom attributes. Cut isCustomAttribute * Cover objects with custom attributes in warning test * Rename DOMProperty.isWriteable to shouldSetAttribute * Rework conditions in shouldSetProperty to avoid edge cases * Update unknown property warning to include custom attribute information * Remove ref and key from reserved props * Ensure SSR test coverage for DOMProperty injections * Add ajaxify attribute for internal FB support * Ajaxify is a stringifiable object attribute * Remove non-case sensitive standard attributes. Make ARIA hook dev only. * Update test name for custom attributes on custom elements * Remove SSR custom injection test * Remove case sensitive props * Remove onAfterResetModules hooks in SSR render tests * Add back a few attributes and explain why they are needed * Remove possibleStandardNames from DOMProperty.js * Fix typo in HTMLPropertyConfig comment * Remove duplicative comment * Add back loop boolean property * Do not allow assignment of attributes that are aliased * Update custom attribute test to check value, not just presence * Address case where class is assigned as an attribute on custom elements. Improve SSR tests * Cover cases where className and for are given to custom elements * Remove unnecessary spys on console.error. Reduce extra space in tests * Cover cased custom attributes in SSR tests * Custom attributes are case sensitive * Allow uppercase letters in custom attributes. Address associated edge cases * Allow improperly cased aliased attributes. Add additional tests * Handle special properties like onFocusOut * Add some comments to document where casing matters. Remove DOMPropertyNames * Fix spelling mistake in ajaxify HTML property comment * Make ARIA enforcement dev-only * Remove alias test that covers multiple aliases for one property * Fix typo in comment * Build SVG aliases dynamically * Remove unused DOMPropertyNames reference * Do not translate bad casings of aliased attributes - classname writes to the DOM as classname - class does not write to the DOM - cLASS does not write to the DOM - arabic-form does not write to the DOM * Revise the way custom booleans are treated - Custom attributes can not have boolean values unless they are aria or data attributes - Attributes with boolean values have been added back to the whitelist - Warnings now exclude booleans from supported types - Associated test coverage * Add developer warnings for NaN and ARIA hooks * Use string comparison instead of regex to check for data and aria attributes. * Warn about unsupported properties without case sensitivity * Remove attributes that are updated to invalid values * Support object property values with toString methods. Allow boolean props to coerce objects * Add back ajaxify test * Address bad references in ReactDOMComponent-test. Format. * Revert changes to the docs We'll update them separately * Allow all objects and pass incorrect aliases
2017-08-16 00:00:45 +08:00
// Warn when passing the strings 'false' or 'true' into a boolean prop
if (
(value === 'false' || value === 'true') &&
propertyInfo !== null &&
propertyInfo.type === BOOLEAN
) {
warning(
false,
'Received the string `%s` for the boolean attribute `%s`. ' +
'%s ' +
'Did you mean %s={%s}?',
value,
name,
value === 'false'
? 'The browser will interpret it as a truthy value.'
: 'Although this works, it will not work as expected if you pass the string "false".',
name,
value,
);
warnedProperties[name] = true;
return true;
}
Custom Attributes Scenario 2: Write badly cased attributes. Remove most of whitelist. (#10385) * Allow custom attributes. Add flag to toggle custom attribute behavior * Update custom attribute logic - Only allow string attributes - Remove custom attribute feature flag - Add additional tests for data, aria, and custom attributes * Allow numbers and booleans custom attributes. Cut isCustomAttribute * Cover objects with custom attributes in warning test * Rename DOMProperty.isWriteable to shouldSetAttribute * Rework conditions in shouldSetProperty to avoid edge cases * Update unknown property warning to include custom attribute information * Remove ref and key from reserved props * Ensure SSR test coverage for DOMProperty injections * Add ajaxify attribute for internal FB support * Ajaxify is a stringifiable object attribute * Remove non-case sensitive standard attributes. Make ARIA hook dev only. * Update test name for custom attributes on custom elements * Remove SSR custom injection test * Remove case sensitive props * Remove onAfterResetModules hooks in SSR render tests * Add back a few attributes and explain why they are needed * Remove possibleStandardNames from DOMProperty.js * Fix typo in HTMLPropertyConfig comment * Remove duplicative comment * Add back loop boolean property * Do not allow assignment of attributes that are aliased * Update custom attribute test to check value, not just presence * Address case where class is assigned as an attribute on custom elements. Improve SSR tests * Cover cases where className and for are given to custom elements * Remove unnecessary spys on console.error. Reduce extra space in tests * Cover cased custom attributes in SSR tests * Custom attributes are case sensitive * Allow uppercase letters in custom attributes. Address associated edge cases * Allow improperly cased aliased attributes. Add additional tests * Handle special properties like onFocusOut * Add some comments to document where casing matters. Remove DOMPropertyNames * Fix spelling mistake in ajaxify HTML property comment * Make ARIA enforcement dev-only * Remove alias test that covers multiple aliases for one property * Fix typo in comment * Build SVG aliases dynamically * Remove unused DOMPropertyNames reference * Do not translate bad casings of aliased attributes - classname writes to the DOM as classname - class does not write to the DOM - cLASS does not write to the DOM - arabic-form does not write to the DOM * Revise the way custom booleans are treated - Custom attributes can not have boolean values unless they are aria or data attributes - Attributes with boolean values have been added back to the whitelist - Warnings now exclude booleans from supported types - Associated test coverage * Add developer warnings for NaN and ARIA hooks * Use string comparison instead of regex to check for data and aria attributes. * Warn about unsupported properties without case sensitivity * Remove attributes that are updated to invalid values * Support object property values with toString methods. Allow boolean props to coerce objects * Add back ajaxify test * Address bad references in ReactDOMComponent-test. Format. * Revert changes to the docs We'll update them separately * Allow all objects and pass incorrect aliases
2017-08-16 00:00:45 +08:00
return true;
};
}
const warnUnknownProperties = function(type, props, canUseEventSystem) {
if (__DEV__) {
const unknownProps = [];
for (const key in props) {
const isValid = validateProperty(
type,
key,
props[key],
canUseEventSystem,
);
if (!isValid) {
unknownProps.push(key);
}
}
const unknownPropString = unknownProps
.map(prop => '`' + prop + '`')
.join(', ');
if (unknownProps.length === 1) {
warning(
false,
'Invalid value for prop %s on <%s> tag. Either remove it from the element, ' +
'or pass a string or number value to keep it in the DOM. ' +
'For details, see https://fb.me/react-attribute-behavior',
unknownPropString,
type,
);
} else if (unknownProps.length > 1) {
warning(
false,
'Invalid values for props %s on <%s> tag. Either remove them from the element, ' +
'or pass a string or number value to keep them in the DOM. ' +
'For details, see https://fb.me/react-attribute-behavior',
unknownPropString,
type,
);
}
}
};
Run 90% of tests on compiled bundles (both development and production) (#11633) * Extract Jest config into a separate file * Refactor Jest scripts directory structure Introduces a more consistent naming scheme. * Add yarn test-bundles and yarn test-prod-bundles Only files ending with -test.public.js are opted in (so far we don't have any). * Fix error decoding for production bundles GCC seems to remove `new` from `new Error()` which broke our proxy. * Build production version of react-noop-renderer This lets us test more bundles. * Switch to blacklist (exclude .private.js tests) * Rename tests that are currently broken against bundles to *-test.internal.js Some of these are using private APIs. Some have other issues. * Add bundle tests to CI * Split private and public ReactJSXElementValidator tests * Remove internal deps from ReactServerRendering-test and make it public * Only run tests directly in __tests__ This lets us share code between test files by placing them in __tests__/utils. * Remove ExecutionEnvironment dependency from DOMServerIntegrationTest It's not necessary since Stack. * Split up ReactDOMServerIntegration into test suite and utilities This enables us to further split it down. Good both for parallelization and extracting public parts. * Split Fragment tests from other DOMServerIntegration tests This enables them to opt other DOMServerIntegration tests into bundle testing. * Split ReactDOMServerIntegration into different test files It was way too slow to run all these in sequence. * Don't reset the cache twice in DOMServerIntegration tests We used to do this to simulate testing separate bundles. But now we actually *do* test bundles. So there is no need for this, as it makes tests slower. * Rename test-bundles* commands to test-build* Also add test-prod-build as alias for test-build-prod because I keep messing them up. * Use regenerator polyfill for react-noop This fixes other issues and finally lets us run ReactNoop tests against a prod bundle. * Run most Incremental tests against bundles Now that GCC generator issue is fixed, we can do this. I split ErrorLogging test separately because it does mocking. Other error handling tests don't need it. * Update sizes * Fix ReactMount test * Enable ReactDOMComponent test * Fix a warning issue uncovered by flat bundle testing With flat bundles, we couldn't produce a good warning for <div onclick={}> on SSR because it doesn't use the event system. However the issue was not visible in normal Jest runs because the event plugins have been injected by the time the test ran. To solve this, I am explicitly passing whether event system is available as an argument to the hook. This makes the behavior consistent between source and bundle tests. Then I change the tests to document the actual logic and _attempt_ to show a nice message (e.g. we know for sure `onclick` is a bad event but we don't know the right name for it on the server so we just say a generic message about camelCase naming convention).
2017-11-24 01:44:58 +08:00
export function validateProperties(type, props, canUseEventSystem) {
Changes to attribute whitelist logic (#10564) * Remove HTMLPropertyConfig entries for non-boolean values When we originally removed attributes from the whitelist, we assumed a few attributes were string booleans, but they are not: Autocomplete ("on", "off") https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/Attributes.html#autocomplete Autocapitalize ("none", "sentence", "words", ...) https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/Attributes.html#autocapitalize Autocorrect ("on", "off") https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/Attributes.html#autocorrect Autosave (string) https://developer.apple.com/library/content/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/Attributes.html#autosave * Only HAS_BOOLEAN_VALUE attribute flag can assign booleans * Use a non-boolean attribute in object assignment tests * Add HAS_STRING_BOOLEAN_VALUE attribute flag * Fix boolean tests, add boolean warning. * Reserved props should allow booleans * Remove outdated comments * Style tweaks * Don't treat dashed SVG tags as custom elements * SVG elements like font-face are not custom attributes - Adds exceptions to isCustomAttribute for dashed SVG elements - Use consistent custom element check across all modules * Move namespace check to isCustomAttribute. Add caveat for stack. * Remove unused namespace variable assignment * Fix the DEV-only whitelist * Don't read property twice * Ignore and warn about non-string `is` attribute * Blacklist "aria" and "data" attributes * Don't pass unknown on* attributes through * Remove dead code * Avoid accessing namespace when possible * Drop .only in ReactDOMComponent-test * Make isCustomComponent logic more solid * Do attribute name check earlier * Fix fbjs import * Revert unintentional edit * Re-allow "data" attribute We intentionally allowed it. * Use stricter check when attaching events * Pass SVG boolean attributes with correct casing * Fix the test * Undo the SVG dashed-name fix Per conversation with @sebmarkbage we decided that the fix is too complicated, and it's unfortunate it depends on the DOM element. It's only relevant for super rare tags that aren't even working consistently across browsers so we'll leave it unfixed for now. * Prettier * Fix lint * Fix flow * Pass "aria" through but still warn * Remove special cases for onfocusin, onfocusout They're covered by event handler code now. * Add a more specific warning for unknown events * Pass badly cased React attributes through with warning
2017-08-31 09:28:55 +08:00
if (isCustomComponent(type, props)) {
return;
}
Run 90% of tests on compiled bundles (both development and production) (#11633) * Extract Jest config into a separate file * Refactor Jest scripts directory structure Introduces a more consistent naming scheme. * Add yarn test-bundles and yarn test-prod-bundles Only files ending with -test.public.js are opted in (so far we don't have any). * Fix error decoding for production bundles GCC seems to remove `new` from `new Error()` which broke our proxy. * Build production version of react-noop-renderer This lets us test more bundles. * Switch to blacklist (exclude .private.js tests) * Rename tests that are currently broken against bundles to *-test.internal.js Some of these are using private APIs. Some have other issues. * Add bundle tests to CI * Split private and public ReactJSXElementValidator tests * Remove internal deps from ReactServerRendering-test and make it public * Only run tests directly in __tests__ This lets us share code between test files by placing them in __tests__/utils. * Remove ExecutionEnvironment dependency from DOMServerIntegrationTest It's not necessary since Stack. * Split up ReactDOMServerIntegration into test suite and utilities This enables us to further split it down. Good both for parallelization and extracting public parts. * Split Fragment tests from other DOMServerIntegration tests This enables them to opt other DOMServerIntegration tests into bundle testing. * Split ReactDOMServerIntegration into different test files It was way too slow to run all these in sequence. * Don't reset the cache twice in DOMServerIntegration tests We used to do this to simulate testing separate bundles. But now we actually *do* test bundles. So there is no need for this, as it makes tests slower. * Rename test-bundles* commands to test-build* Also add test-prod-build as alias for test-build-prod because I keep messing them up. * Use regenerator polyfill for react-noop This fixes other issues and finally lets us run ReactNoop tests against a prod bundle. * Run most Incremental tests against bundles Now that GCC generator issue is fixed, we can do this. I split ErrorLogging test separately because it does mocking. Other error handling tests don't need it. * Update sizes * Fix ReactMount test * Enable ReactDOMComponent test * Fix a warning issue uncovered by flat bundle testing With flat bundles, we couldn't produce a good warning for <div onclick={}> on SSR because it doesn't use the event system. However the issue was not visible in normal Jest runs because the event plugins have been injected by the time the test ran. To solve this, I am explicitly passing whether event system is available as an argument to the hook. This makes the behavior consistent between source and bundle tests. Then I change the tests to document the actual logic and _attempt_ to show a nice message (e.g. we know for sure `onclick` is a bad event but we don't know the right name for it on the server so we just say a generic message about camelCase naming convention).
2017-11-24 01:44:58 +08:00
warnUnknownProperties(type, props, canUseEventSystem);
}