Commit Graph

483 Commits

Author SHA1 Message Date
Dominic Gannaway
a41b217708 Add additional event API responder surfaces (#15248)
* Add rest of event modules + small fixes
2019-03-29 10:31:18 -07:00
Dominic Gannaway
5d336df706 Allow for null targetFiber for root event handling (#15247) 2019-03-28 21:43:19 -07:00
Dominic Gannaway
c6f3524df5 Adds React event component and React event target support to SSR renderer (#15242)
* Adds React event component and React event target support to SSR renderer
2019-03-28 15:36:21 -07:00
Dominic Gannaway
1cfd256685 Fix circular module imports causing file size increase (#15231)
* Fix circular module imports causing file size increase
2019-03-27 21:17:58 -07:00
Dominic Gannaway
669cafb36f Adds experimental event component responder surfaces (#15228)
* Adds Press and Hover event modules + more features to the Event Responder System
2019-03-27 16:42:17 -07:00
Brian Vaughn
d8cb10f11f Enabled warnAboutDeprecatedLifecycles flag by default (#15186) 2019-03-27 16:30:49 -07:00
Dominic Gannaway
80f8b0d512 Add part of the event responder system for experimental event API (#15179)
* Add part of the event responder system
2019-03-26 16:55:25 -07:00
Dan Abramov
5c2b2c0852 Warn about async infinite useEffect loop (#15180)
* Warn about async infinite useEffect loop

* Make tests sync
2019-03-22 20:04:34 +00:00
Dominic Gannaway
78f2775ed0 Flip event passive logic on passiveBrowserEventsSupported (#15190) 2019-03-22 10:28:03 +00:00
Brian Vaughn
56035dac64 unstable_Profiler -> Profiler (#15172) 2019-03-21 09:18:34 -07:00
Dan Abramov
31518135c2 Strengthen nested update counter test coverage (#15166)
* Isolate ReactUpdates-test cases

This ensures their behavior is consistent when run in isolation, and that they actually test the cases they're describing.

* Add coverage for cases where we reset nestedUpdateCounter

These cases explicitly verify that we reset the counter in right places.

* Add a mutually recursive test case

* Add test coverage for useLayoutEffect loop
2019-03-21 14:52:51 +00:00
Dominic Gannaway
66f280c87b Add internal logic for listening to event responders (#15168)
* Add the logic for listening to event responders
2019-03-21 12:32:40 +00:00
Dan Abramov
c05b4b81f9 Link to useLayoutEffect gist in a warning (#15158) 2019-03-20 13:40:36 +00:00
Renan Valentin
061d6ce3c0 fix(react-dom): access iframe contentWindow instead of contentDocument (#15099)
MDN has a list of methods for obtaining the window reference of an
iframe:

https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage#Syntax

fix(react-dom): check if iframe belongs to the same origin

Accessing the contentDocument of a HTMLIframeElement can cause the browser
to throw, e.g. if it has a cross-origin src attribute.
Safari will show an error in the console when the access results in "Blocked a frame with origin". e.g:

```javascript
try {
 $0.contentDocument.defaultView
} catch (err) {
  console.log('err', err)
}

> Blocked a frame with origin X from accessing a frame with origin Y. Protocols, domains, and ports must match.
> err – TypeError: null is not an object (evaluating '$0.contentDocument.defaultView')
```

A safety way is to access one of the cross origin properties: Window or Location
Which might result in "SecurityError" DOM Exception and it is compatible to Safari.

```javascript
try {
 $0.contentWindow.location.href
} catch (err) {
 console.log('err', err)
}

> err – SecurityError: Blocked a frame with origin "http://localhost:3001" from accessing a cross-origin frame. Protocols, domains, and ports must match.
```

https://html.spec.whatwg.org/multipage/browsers.html#integration-with-idl
2019-03-20 13:11:54 +00:00
Dominic Gannaway
b83e01cade Adds more scaffolding for experimental event API (#15112)
* Adds more scaffolding for experimental event API
2019-03-20 11:20:17 +00:00
Sebastian Markbåge
acd65db5bc Deprecate module pattern (factory) components (#15145) 2019-03-19 12:55:27 -07:00
Dan Abramov
7ad7386308 Improve warning for invalid class contextType (#15142)
* Improve warning for invalid class contextType

* Don't warn for null

* Grammar
2019-03-19 13:31:26 +00:00
Sebastian Markbåge
1e3364e764 Test that we don't suspend when disabling yielding (#15143) 2019-03-18 15:21:49 -07:00
Brandon Dail
df7b87d25e Warn for Context.Consumer with contextType (#14831) 2019-03-18 19:27:05 +00:00
Jared Palmer
2b93d686e3 Add more info to invalid hook call error message (#15139)
* Add more info to invalid hook call error message

* Update other renderers + change call to action

* Update related tests for new hooks error message

* Fix lint errors
2019-03-18 18:22:38 +00:00
Sebastian Markbåge
4162f6026c Add feature flag to disable yielding (#15119) 2019-03-15 15:54:22 -07:00
Dominic Gannaway
035e4cffbd Change passive checker to use defineProperty (#15121) 2019-03-15 22:24:25 +00:00
Dominic Gannaway
371bbf36bb Add infrastructure for passive/non-passive event support for future API exploration (#15036)
* Add infrastructure for passive/non-passive event support for future event API experimentation
2019-03-15 09:39:43 +00:00
Mateusz
ab5fe174c6 Don't set the first option as selected in select tag with size attribute (#14242)
* Set 'size' attribute to select tag if it occurs before appending options

* Add comment about why size is assigned on select create. Tests

I added some more clarification for why size must be set on select
element creation:

- In the source code
- In the DOM test fixture
- In a unit test

* Use let, not const in select tag stub assignment
2019-03-14 14:40:09 -07:00
Dominic Gannaway
0c03a47436 Adds experimental event API scaffolding (#15108)
* Adds experimental event API scaffolding
2019-03-14 17:02:42 +00: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
Sebastian Markbåge
5d0c3c6c7d [Partial Hydration] Render client-only content at normal priority (#15061)
* Split props changing from permanent fallback state

These will need different logic. In this commit, no logic has changed,
only moved.

* Delete terminal fallback content in first pass

If the dehydrated suspense boundary's fallback content is terminal there
is nothing to show. We need to get actual content on the screen soon.

If we deprioritize that work to offscreen, then the timeout heuristics will
be wrong.

Therefore, if we have no current and we're already at terminal fallback
state we'll immediately schedule a deletion and upgrade to real suspense.

* Show failing case when there is another wrapper boundary

* Revert "Delete terminal fallback content in first pass"

This reverts commit ad67ba8928.

* Use the new approach of leaving work at normal pri to replace fallback
2019-03-11 13:50:19 -07:00
Andrew Clark
1e3b6192b5 Import Scheduler directly, not via host config (#14984)
* Import Scheduler directly, not via host config

We currently schedule asynchronous tasks via the host config. (The host
config is a static/build-time dependency injection system that varies
across different renderers — DOM, native, test, and so on.) Instead of
calling platform APIs like `requestIdleCallback` directly, each renderer
implements a method called `scheduleDeferredCallback`.

We've since discovered that when scheduling tasks, it's crucial that
React work is placed in the same queue as other, non-React work on the
main thread. Otherwise, you easily end up in a starvation scenario where
rendering is constantly interrupted by less important tasks. You need a
centralized coordinator that is used both by React and by other
frameworks and application code. This coordinator must also have a
consistent API across all the different host environments, for
convention's sake and so product code is portable — e.g. so the same
component can work in both React Native and React Native Web.

This turned into the Scheduler package. We will have different builds of
Scheduler for each of our target platforms. With this approach, we treat
Scheduler like a built-in platform primitive that exists wherever React
is supported.

Now that we have this consistent interface, the indirection of the host
config no longer makes sense for the purpose of scheduling tasks. In
fact, we explicitly do not want renderers to scheduled task via any
system except the Scheduler package.

So, this PR removes `scheduleDeferredCallback` and its associated
methods from the host config in favor of directly importing Scheduler.

* Missed an extraneous export
2019-03-06 14:41:45 -08:00
Dan Abramov
02404d793b Avoid dynamic dispatch for scheduler calls (#14968) 2019-03-01 15:04:15 +00:00
Andrew Clark
00748c53e1 Add new mock build of Scheduler with flush, yield API (#14964)
* Add new mock build of Scheduler with flush, yield API

Test environments need a way to take control of the Scheduler queue and
incrementally flush work. Our current tests accomplish this either using
dynamic injection, or by using Jest's fake timers feature. Both of these
options are fragile and rely too much on implementation details.

In this new approach, we have a separate build of Scheduler that is
specifically designed for test environments. We mock the default
implementation like we would any other module; in our case, via Jest.
This special build has methods like `flushAll` and `yieldValue` that
control when work is flushed. These methods are based on equivalent
methods we've been using to write incremental React tests. Eventually
we may want to migrate the React tests to interact with the mock
Scheduler directly, instead of going through the host config like we
currently do.

For now, I'm using our custom static injection infrastructure to create
the two builds of Scheduler — a default build for DOM (which falls back
to a naive timer based implementation), and the new mock build. I did it
this way because it allows me to share most of the implementation, which
isn't specific to a host environment — e.g. everything related to the
priority queue. It may be better to duplicate the shared code instead,
especially considering that future environments (like React Native) may
have entirely forked implementations. I'd prefer to wait until the
implementation stabilizes before worrying about that, but I'm open to
changing this now if we decide it's important enough.

* Mock Scheduler in bundle tests, too

* Remove special case by making regex more restrictive
2019-02-26 20:51:17 -08:00
Nathan Hunzaker
d0318fb3f9 Updating copyright headers, dropping the year (#14893)
* Updating copyright headers, dropping the year
* Update copyright in ReactDOMHooks-test and react-cache LRU.js
2019-02-21 08:46:13 -08:00
Sebastian Markbåge
13645d224d Deal with fallback content in Partial Hydration (#14884)
* Replace SSR fallback content with new suspense content

* The three states of a Dehydrated Suspense

This introduces three states for dehydrated suspense boundaries

Pending - This means that the tree is still waiting for additional data or
to be populated with its final content.

Fallback - This means that the tree has entered a permanent fallback state
and no more data from the server is to be expected. This means that the
client should take over and try to render instead. The fallback nodes will
be deleted.

Normal - The node has entered its final content and is now ready to be
hydrated.

* Rename retryTimedOutBoundary to resolveRetryThenable

This doesn't just retry. It assumes that resolving a thenable means that
it is ok to clear it from the thenable cache.

We'll reuse the retryTimedOutBoundary logic separately.

* Register a callback to be fired when a boundary changes away from pending

It's now possible to switch from a pending state to either hydrating
or replacing the content.
2019-02-19 13:07:41 -08:00
overlookmotel
ab7a67b1dc Fix react-dom/server context leaks when render stream destroyed early (#14706)
* Fix react-dom/server context memory retention

* Test for pollution of later renders

* Inline loop

* More tests
2019-02-14 19:50:23 +00:00
Sunil Pai
c555c008b6 Include component stack in 'act(...)' warning (#14855)
* add a component stack trace to the act() warning

* pass tests

* nit
2019-02-14 17:20:49 +00:00
Deniz Susman
c4d8ef6430 Fix typo in code comment (#14836) 2019-02-13 20:49:37 -08:00
Brandon Dail
fa6205d522 Special case crossOrigin for SVG image elements (#14832) 2019-02-12 20:13:17 -08:00
Dan Abramov
3ae94e1885 Fix ignored sync work in passive effects (#14799)
* Fix ignored sync work in passive effects

* Fix batching
2019-02-12 20:18:35 +00:00
Sebastian Markbåge
f3a14951ab Partial Hydration (#14717)
* Basic partial hydration test

* Render comments around Suspense components

We need this to be able to identify how far to skip ahead if we're not
going to hydrate this subtree yet.

* Add DehydratedSuspenseComponent type of work

Will be used for Suspense boundaries that are left with their server
rendered content intact.

* Add comment node as hydratable instance type as placeholder for suspense

* Skip past nodes within the Suspense boundary

This lets us continue hydrating sibling nodes.

* A dehydrated suspense boundary comment should be considered a sibling

* Retry hydrating at offscreen pri or after ping if suspended

* Enter hydration state when retrying dehydrated suspense boundary

* Delete all children within a dehydrated suspense boundary when it's deleted

* Delete server rendered content when props change before hydration completes

* Make test internal

* Wrap in act

* Change SSR Fixture to use Partial Hydration

This requires the enableSuspenseServerRenderer flag to be manually enabled
for the build to work.

* Changes to any parent Context forces clearing dehydrated content

We mark dehydrated boundaries as having child work, since they might have
components that read from the changed context.

We check this in beginWork and if it does we treat it as if the input
has changed (same as if props changes).

* Wrap in feature flag

* Treat Suspense boundaries without fallbacks as if not-boundaries

These don't come into play for purposes of hydration.

* Fix clearing of nested suspense boundaries

* ping -> retry

Co-Authored-By: sebmarkbage <sebastian@calyptus.eu>

* Typo

Co-Authored-By: sebmarkbage <sebastian@calyptus.eu>

* Use didReceiveUpdate instead of manually comparing props

* Leave comment for why it's ok to ignore the timeout
2019-02-11 21:25:44 -08:00
Dan Abramov
1fecba9230 Fix crash unmounting an empty Portal (#14820)
* Adds failing test for https://github.com/facebook/react/issues/14811

* Fix removeChild() crash when removing an empty Portal
2019-02-11 18:37:53 +00:00
Sebastian Markbåge
1d48b4a684 Fix hydration with createRoot warning (#14808)
It's suggesting an API that doesn't exist. Fixed it to reference the actual
API.
2019-02-09 17:12:11 +00:00
Sunil Pai
1107b9673c [TestUtils.act] warn when using TestUtils.act in node (#14768)
* warn when using TestUtils.act in node

* s/warns/throws

* s/throw/warn

* consistent ellipses
2019-02-06 16:25:26 +00:00
Sunil Pai
d1326f466a [TestUtils.act] fix return result checking (#14758)
* fix .act return value testing when result === null

* nit
2019-02-05 17:34:21 +00:00
Sunil Pai
267ed98146 expose TestUtils.act() for batching actions in tests (#14744)
* expose unstable_interact for batching actions in tests

* move to TestUtils

* move it all into testutils

* s/interact/act

* warn when calling hook-like setState outside batching mode

* pass tests

* merge-temp

* move jsdom test to callsite

* mark failing tests

* pass most tests (except one)

* augh IE

* pass fuzz tests

* better warning, expose the right batchedUpdates on TestRenderer for www

* move it into hooks, test for dom

* expose a flag on the host config, move stuff around

* rename, pass flow

* pass flow... again

* tweak .act() type

* enable for all jest environments/renderers; pass (most) tests.

* pass all tests

* expose just the warning from the scheduler

* don't return values

* a bunch of changes.

can't return values from .act
don't try to await .act calls
pass tests

* fixes and nits

* "fire events that udpates state"

* nit

* 🙄

* my bad

* hi andrew

(prettier fix)
2019-02-05 16:10:16 +00:00
Andrew Clark
fb3f7bfde9 Avoid importing Scheduler directly (#14757)
* Avoid importing Scheduler directly

The reconciler should not depend directly on Scheduler. This adds it to
the host config for the renderer instead.

(Except for `scheduler/tracing` imports, which are used only by the
profiling build. I've left those imports as-is, though I'm open to
directing those through the host config, too.)

* Make throwaway root id longer to appease Brian
2019-02-05 03:21:25 -08:00
Dan Abramov
c21c41ecfa Tweak invalid Hook warning and error (#14747) 2019-02-01 21:05:13 +00:00
Andrew Clark
66eb293742 Restrict effect return type to a function or nothing (#14119)
* Restrict effect return type to a function or nothing

We already warn in dev if the wrong type is returned. This updates the
Flow type.

* Restrict return type further

* Assume Effect hook returns either a function or undefined

* Tweak warning message
2019-01-31 10:11:47 -08:00
Dan Abramov
51c07912ac Warn when second argument is passed to useCallback (#14729) 2019-01-31 13:56:48 +00:00
Andrew Clark
ba6477aa3c Improve Reducer Hook's lazy init API (#14723)
* Improve Reducer Hook's lazy init API

* Use generic type for initilizer input

Still requires an `any` cast in the case where `init` function is
not provided.
2019-01-29 17:39:24 -08:00
Andrew Clark
cb1ff430e8 Phased dispatcher (#14701)
* Move DEV-only function right above where it's used

I don't like looking at this top-level function #petty

* Use different dispatchers for functions & classes

Classes support readContext, but not any of the other dispatcher
methods. Function support all methods.

This is a more robust version of our previous strategy of checking
whether `currentlyRenderingFiber` is null.

As a next step, we can use a separate dispatcher for each phase of the
render cycle (mount versus update).

* Use separate dispatchers for mount and update

* Remove mount code from update path

Deletes mount-specific code from the update path, since it should be
unreachable. To continue supporting progressive enhancement (mounting
new hooks at the end of the list), we detect when there are no more
current hooks and switch back to the mount dispatcher. Progressive
enhancement isn't officially supported yet, so it will continue to warn.

* Factoring nits

* Fix Flow

Had to cheat more than I would like

* More Flow nits

* Switch back to using a special dispatcher for nested hooks in DEV

In order for this strategy to work, I had to revert progressive
enhancement support (appending hooks to the end). It was previously a
warning but now it results in an error. We'll reconsider later.

* Always pass args to updateState and updateReducer

Even though the extra args are only used on mount, to ensure
type consistency.
2019-01-29 16:32:15 -08:00
Brian Vaughn
f11a9c1cb0 State update bug in concurrent mode (#14698)
* State update bug in concurrent mode

* Fix bug introduced by double-rendering Functions using hooks
2019-01-24 16:10:13 -08:00