Commit Graph

63 Commits

Author SHA1 Message Date
Brian Vaughn
b1a03dfdc8 Rename legacy "events" package to "legacy-events" (#16388)
* Renamed 'events' package to 'legacy-events'
* Updated 'events' references to point to 'legacy-events'
2019-08-14 07:32:42 -07:00
Dominic Gannaway
42794557ca [Flare] Tweaks to Flare system design and API (#16264) 2019-08-01 19:08:54 +01:00
Belmin Bedak
858c84206e Don't hyphenate custom CSS properties for ReactDOMServer (#16167)
* Do not hyphenate custom CSS property

* Move check into the processStyleName fn

* Formatting

* add test

* Put isCustomProperty check after conditional return

* add test to `ReactDOMServerIntegration` and supress warning

* Don't indexOf twice

* Simpler fix
2019-07-26 18:06:24 +01:00
Dominic Gannaway
5098891193 [Flare] Redesign core event system (#16163) 2019-07-23 23:46:44 +01:00
Dominic Gannaway
65b80fdd94 [Flare] Add Input event responder surface (#16148) 2019-07-17 21:04:41 +01:00
Dominic Gannaway
8b88ac2592 [Flare] Remove event targets including TouchHitTarget (#16011) 2019-06-27 23:58:48 +01:00
Dominic Gannaway
b0657fde6a Event API: ensure getFocusableElementsInScope handles suspended trees (#15651) 2019-05-15 01:08:30 +01:00
Dominic Gannaway
d38cfd452f Ensure TouchHitTarget element is server side rendered with hit slop (#15385)
* Follow up to 15381

* Add back in hit slop properties

* Prettier

* Fix lint

* move hydration update out of DEV block

* Remove pointer-events:auto
2019-05-06 20:13:23 +01:00
Radu-Sebastian Amarie
f85aadefc0 ADD: disablePictureInPicture attribute for HTML5 videos (#15334)
* ADD: disablePictureInPicture attribute for HTML5 videos

* ADD: disablePictureInPicture as DOMProperty and attribute

* Update: Replace camelCase with lowercase and vice-versa

* FIX: Missing comma on attribute (prettier)
2019-04-25 12:02:27 +01:00
Dominic Gannaway
64e3da286f Event API: Add FocusScope surface (#15487) 2019-04-25 02:01:09 +01:00
Sebastian Markbåge
103378b1ea Warn for javascript: URLs in DOM sinks (#15047)
* Prevent javascript protocol URLs

* Just warn when disableJavaScriptURLs is false

This avoids a breaking change.

* Allow framesets

* Allow <html> to be used in integration tests

Full document renders requires server rendering so the client path
just uses the hydration path in this case to simplify writing these tests.

* Detect leading and intermediate characters and test mixed case

These are considered valid javascript urls by browser so they must be
included in the filter.

This is an exact match according to the spec but maybe we should include
a super set to be safer?

* Test updates to ensure we have coverage there too

* Fix toString invocation and Flow types

Right now we invoke toString twice when we hydrate (three times
with the flag off). Ideally we should only do it once even in this case
but the code structure doesn't really allow for that right now.

* s/itRejects/itRejectsRendering

* Dedupe warning and add the unsafe URL to the warning message

* Add test that fails if g is added to the sanitizer

This only affects the prod version since the warning is deduped anyway.

* Fix prod test
2019-03-11 16:39:49 -07:00
Brandon Dail
fa6205d522 Special case crossOrigin for SVG image elements (#14832) 2019-02-12 20:13:17 -08:00
Andrew Clark
21d5f7d32d Wrap shorthand CSS property collision warning in feature flag (#14245)
Disables the recently introduced (#14181) warning for shorthand
CSS property collisions by wrapping in a feature flag. Let's hold off
shipping this until at least the next minor.
2018-11-15 13:36:52 -08:00
Sophie Alpert
b98adb648a Simplify CSS shorthand property warning (#14183)
I figured out a simpler way to do #14181. It does allocate some but I think that's OK. Time complexity might even be better since we avoid the nested loops the old one had.
2018-11-09 16:56:51 -08:00
Sophie Alpert
8ae867e6b5 Warn about conflicting style values during updates (#14181)
This is one of the most insidious quirks of React DOM that people run into. Now we warn when we think an update is dangerous.

We still allow rendering `{background, backgroundSize}` with unchanging values, for example. But once you remove either one or change `background` (without changing `backgroundSize` at the same time), that's bad news. So we warn.

Fixes #6348.
2018-11-09 15:21:47 -08:00
Héctor Ramos
b87aabdfe1 Drop the year from Facebook copyright headers and the LICENSE file. (#13593) 2018-09-07 15:11:23 -07:00
Michał Gołębiowski-Owczarek
25d48a7281 Add gridArea to unitless CSS properties (#13550)
Ref #9185
2018-09-04 12:22:21 +01:00
Heaven
d400d6d5ef Replace magic number 1 with ELEMENT_NODE (#13479)
* Replace magic number 1 with ELEMENT_NODE

* Add flow pragma to HTMLNodeType
2018-08-27 08:16:24 -07:00
Nathan Hunzaker
0cd8d470da Do not toLowerCase lists of lowercase words (#13428)
* Do not toLowerCase lists of lowercase words

* Add notes about downcasing to DOMProperty.js

* Use consistent comment breakout

* Make toLowerCase more obvious
2018-08-17 19:52:30 -07:00
Moti Zilberman
2c59076d26 Warn when "false" or "true" is the value of a boolean DOM prop (#13372)
* Warn when the string "false" is the value of a boolean DOM prop

* Only warn on exact case match for "false" in DOM boolean props

* Warn on string "true" as well as "false" in DOM boolean props

* Clarify warnings on "true" / "false" values in DOM boolean props
2018-08-14 20:51:33 +01:00
Dan Abramov
3cfab14b96 Treat focusable as enumerated boolean SVG attribute (#13339)
* Treat focusable as enumerated boolean attribute

* Update attribute table
2018-08-07 19:39:56 +01:00
Dan Abramov
470377bbdb Remove extraneous condition
It's covered by a check below.
2018-08-02 02:33:54 +01:00
Dan Abramov
f60a7f722c Fix SSR crash on a hasOwnProperty attribute (#13303) 2018-08-01 20:23:19 +01:00
Nicole Levy
171e0b7d44 Fix “no onChange handler” warning to fire on falsy values ("", 0, false) too (#12628)
* throw warning for falsey `value` prop

* add nop onChange handler to tests for `value` prop

* prettier

* check for falsey checked

* fix tests for `checked` prop

* new tests for `value` prop

* test formatting

* forgot 0 (:

* test for falsey `checked` prop

* add null check

* Update ReactDOMInput-test.js

* revert unneeded change

* prettier

* Update DOMPropertyOperations-test.js

* Update ReactDOMInput-test.js

* Update ReactDOMSelect-test.js

* Fixes and tests

* Remove unnecessary changes
2018-07-17 22:46:43 +01:00
Dan Abramov
82c7ca4cca Add component stacks to some warnings (#13218) 2018-07-17 20:15:03 +01:00
Dan Abramov
f9358c51c8 Change warning() to automatically inject the stack, and add warningWithoutStack() as opt-out (#13161)
* Use %s in the console calls

* Add shared/warningWithStack

* Convert some warning callsites to warningWithStack

* Use warningInStack in shared utilities and remove unnecessary checks

* Replace more warning() calls with warningWithStack()

* Fixes after rebase + use warningWithStack in react

* Make warning have stack by default; warningWithoutStack opts out

* Forbid builds that may not use internals

* Revert newly added stacks

I changed my mind and want to keep this PR without functional changes. So we won't "fix" any warnings that are already missing stacks. We'll do it in follow-ups instead.

* Fix silly find/replace mistake

* Reorder imports

* Add protection against warning argument count mismatches

* Address review
2018-07-16 22:31:59 +01:00
Dan Abramov
659a29cecf Reorganize how shared internals are accessed (#13201)
* Reorganize how shared internals are accessed

* Update forks.js
2018-07-13 02:45:37 +01:00
Dan Abramov
96d38d178a Fix concatenation of null to a warning message (#13166) 2018-07-09 13:56:24 +01:00
Dan Abramov
aeda7b745d Remove fbjs dependency (#13069)
* Inline fbjs/lib/invariant

* Inline fbjs/lib/warning

* Remove remaining usage of fbjs in packages/*.js

* Fix lint

* Remove fbjs from dependencies

* Protect against accidental fbjs imports

* Fix broken test mocks

* Allow transitive deps on fbjs/ for UMD bundles

* Remove fbjs from release script
2018-06-19 16:03:45 +01:00
Dan Abramov
ae14317d68 Inline fbjs/lib/emptyFunction (#13054) 2018-06-15 18:45:14 +01:00
Dan Abramov
72434a7686 Remove or inline some fbjs dependencies (#13046) 2018-06-15 18:12:45 +01:00
Airam
dcc854bcc3 prevent removing attributes on custom component tags (#12702) 2018-04-28 20:52:30 +01:00
Brandon Dail
280acbcb71 Initialize React prop name/attribute name mapping without Map (#12353)
Using `new Map(iterable)` isn't supported in IE11, so it ends up trying to iterate through an empty map and these attributes don't get defined in properties. Since this is only run once on startup inlining the attributeName array is probably fine.
2018-03-12 17:42:17 +00:00
Brandon Dail
9ff3ce67ea Add noModule boolean attribute (#11900) 2017-12-22 18:18:51 +00:00
Dan Abramov
4c3470eef8 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-10 16:58:38 +00:00
Dan Abramov
d9869a4561 Revert "Refactor DOM attribute code (#11804)" (#11814)
This reverts commit 47783e878d.
2017-12-08 21:05:34 +00:00
Dan Abramov
47783e878d Refactor DOM attribute code (#11804)
* 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)
2017-12-08 20:42:24 +00:00
Brandon Dail
6e258c1266 Move isAttributeNameSafe to DOMProperty (#11802) 2017-12-07 17:23:02 -08:00
Raphael Amorim
37e4329bc8 Remove vars (#11766)
* react: convert packages/react

* react-reconciler: convert packages/react-reconciler

* react-noop-renderer: convert packages/react-noop-renderer

* react-dom: convert packages/react-dom/src/shared

* react-dom: convert packages/react-dom/src/server
2017-12-05 13:47:57 +00:00
Nathan Hunzaker
323efbc33c Ensure value and defaultValue do not assign functions and symbols (#11741)
* Ensure value and defaultValue do not assign functions and symbols

* Eliminate assignProperty method from ReactDOMInput

* Restore original placement of defaultValue reservedProp

* Reduce branching. Make assignment more consistent

* Control for warnings in symbol/function tests

* Add boolean to readOnly assignments

* Tweak the tests

* Invalid value attributes should convert to an empty string

* Revert ChangeEventPlugin update. See #11746

* Format

* Replace shouldSetAttribute call with value specific type check

DOMProperty.shouldSetAttribute runs a few other checks that aren't
appropriate for determining if a value or defaultValue should be
assigned on an input. This commit replaces that call with an input
specific check.

* Remove unused import

* Eliminate unnecessary numeric equality checks (#11751)

* Eliminate unnecessary numeric equality checks

This commit changes the way numeric equality for number inputs works
such that it compares against `input.valueAsNumber`. This eliminates
quite a bit of branching around numeric equality.

* There is no need to compare valueAsNumber

* Add test cases for empty string to 0.

* Avoid implicit boolean JSX props

* Split up numeric equality test to isolate eslint disable command

* Fix typo in ReactDOMInput test

* Add todos

* Update the attribute table
2017-12-04 14:39:32 +00:00
Dan Abramov
8ec2ed4089 Move HTML and SVG configs into DOMProperty (#11728)
* Inline HTML and SVG configs into DOMProperty

* Replace invariants with warnings

These invariants can only happen if *we* mess up, and happen during init time.
So it's safe to make these warnings, as they would fail the tests anyway.

* Clearer variable naming
2017-11-30 22:29:58 +00:00
Nathan Hunzaker
fd69c239a0 Use defaultValue instead of setAttribute('value') (#11534)
* Use defaultValue instead of setAttribute('value')

This commit replaces the method of synchronizing an input's value
attribute from using setAttribute to assigning defaultValue. This has
several benefits:

- Fixes issue where IE10+ and Edge password icon disappears (#7328)
- Fixes issue where toggling input types hides display value on dates
  in Safari (unreported)
- Removes mutationMethod behaviors from DOMPropertyOperations

* initialValue in Input wrapperState is always a string

* The value property is assigned before the value attribute. Fix related tests.

* Remove initial value tests in ReactDOMInput

I added these tests after removing the `value` mutation
method. However they do not add any additional value over existing
tests.

* Improve clarity of value checks in ReactDOMInput.postMountWrapper

* Remove value and defaultValue from InputWithWrapperState type

They are already included in the type definition for HTMLInputElement

* Inline stringification of value in ReactDOMInput

Avoids eagier stringification and makes usage more consistent.

* Use consistent value/defaultValue presence in postMountHook

Other methods in ReactDOMInput check for null instead of
hasOwnProperty.

* Add missing semicolon

* Remove unused value argument in ReactDOMInput test

* Address cases where a value switches to undefined

When a controlled input value switches to undefined, it reverts back
to the initial state of the controlled input.

We didn't have test coverage for this case, so I've added two describe
blocks to cover both null and undefined.
2017-11-30 21:24:55 +00:00
Jeremias Menichelli
cafe352c1a Drop .textContent IE8 polyfill and rewrite escaping tests against public API (#11331)
* Rename escapeText util. Test quoteAttributeValueForBrowser through ReactDOMServer API

* Fix lint errors

* Prettier reformatting

* Change syntax to prevent prettier escape doble quote

* Name and description gardening. Add tests for escapeTextForBrowser. Add missing tests

* Improve script tag as text content test

* Update escapeTextForBrowser-test.js

* Update quoteAttributeValueForBrowser-test.js

* Simplify tests

* Move utilities to server folder
2017-11-23 22:41:28 +00:00
Dan Abramov
fa7a97fc46 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-23 17:44:58 +00:00
Dan Abramov
afc5fab26c Don't emit autoFocus={false} attribute on the server (#11543) 2017-11-13 15:22:12 +00:00
Max Schmeling
2fe3494f0d Support string values for capture attribute. (#11424)
* Uses HAS_OVERLOADED_BOOLEAN_VALUE instead of HAS_BOOLEAN_VALUE
  * Allows for <input type="file" capture="user" />
Fixes #11419
2017-11-12 09:29:27 -05:00
Clement Hoang
94f44aeba7 Update prettier to 1.8.1 (#10785)
* Change prettier dependency in package.json version 1.8.1

* Update yarn.lock

* Apply prettier changes

* Fix ReactDOMServerIntegration-test.js

* Fix test for ReactDOMComponent-test.js
2017-11-07 18:09:33 +00:00
Joe Lim
e2e7fcce7e switch ordering of logical and (#11462) 2017-11-05 14:46:46 +00:00
Dan Abramov
92b7b172cc Use named exports in more places (#11457)
* Convert EventPlugin{Hub,Registry} to named exports

* Convert EventPluginUtils to named exports

* Convert EventPropagators to named exports

* Convert ReactControlledComponent to named exports

* Convert ReactGenericBatching to named exports

* Convert ReactDOMComponentTree to named exports

* Convert ReactNativeComponentTree to named exports

* Convert ReactNativeRTComponentTree to named exports

* Convert FallbackCompositionState to named exports

* Convert ReactEventEmitterMixin to named exports

* Convert ReactBrowserEventEmitter to named exports

* Convert ReactNativeEventEmitter to named exports

* Convert ReactDOMEventListener to named exports

* Convert DOMMarkupOperations to named exports

* Convert DOMProperty to named exports

* Add suppression for existing Flow violation

Flow didn't see it before.

* Update sizes
2017-11-05 11:58:36 +00:00
Dan Abramov
45c1ff348e Remove unnecessary 'use strict' in the source (#11433)
* Remove use strict from ES modules

* Delete unused file

This was unused since Stack.
2017-11-02 20:32:48 +00:00