Commit Graph

10607 Commits

Author SHA1 Message Date
SamCortopassi 38247cba36 --save is no longer needed (#14302)
`--save` is on by default as of npm 5. `npm install create-subscription` is equivalent to `npm install --save create-subscription` now
2019-01-23 14:13:05 +00:00
Ramón Chancay Ortega 3f0bcaf0db Importing React for the first example. (#14346) 2019-01-23 14:10:03 +00:00
Sunil Pai ecd919a2f9
RFC: warn when returning different hooks on subsequent renders (#14585)
* warn when returning different hooks on next render

like it says. adds a field to Hook to track effect 'type', and compares when cloning subsequently.

* lint

* review changes

- numbered enum for hook types
- s/hookType/_debugType
- better dce

* cleaner detection location

* redundant comments

* different EffectHook / LayoutEffectHook

* prettier

* top level currentHookType

* nulling currentHookType

need to verify dce still works

* small enhancements

* hook order checks for useContext/useImperative

* prettier

* stray whitespace

* move some bits around

* better errors

* pass tests

* lint, flow

* show a before - after diff

* an error stack in the warning

* lose currentHookMatches, fix a test

* tidy

* clear the mismatch only in dev

* pass flow

* side by side diff

* tweak warning

* pass flow

* dedupe warnings per fiber, nits

* better format

* nit

* fix bad merge, pass flow

* lint

* missing hooktype enum

* merge currentHookType/currentHookNameInDev, fix nits

* lint

* final nits
2019-01-22 22:40:07 +00:00
Dan Abramov 3fbebb2a0b
Revert "Double-render function components with Hooks in DEV in StrictMode" (#14652)
* Revert "Revert "Disallow reading context during useMemo etc" (#14651)"

This reverts commit 5fce6488ce.

* Revert "Add test coverage for readContext() on the server (#14649)"

This reverts commit fe2ecd276e.

* Revert "Warn about incorrect use of useImperativeHandle() (#14647)"

This reverts commit 8f45a7fdc4.

* Revert "Disallow reading context during useMemo etc (#14648)"

This reverts commit 1fcbd22431.

* Revert "Warn about refs on lazy function components (#14645)"

This reverts commit 2a084f51a9.

* Revert "Fix typo (#14560)"

This reverts commit b5a3df6e88.

* Revert "fix typo (#14316)"

This reverts commit 9c146e6751.

* Revert "Mention forwardRef() in <Fn ref={...} /> errors and warnings (#14644)"

This reverts commit baa6d40fc8.

* Revert "Double-render function components with Hooks in DEV in StrictMode (#14643)"

This reverts commit a1414e8949.
2019-01-21 20:34:38 +00:00
Dan Abramov 5fce6488ce
Revert "Disallow reading context during useMemo etc" (#14651)
* Revert "Add test coverage for readContext() on the server (#14649)"

This reverts commit fe2ecd276e.

* Revert "Warn about incorrect use of useImperativeHandle() (#14647)"

This reverts commit 8f45a7fdc4.

* Revert "Disallow reading context during useMemo etc (#14648)"

This reverts commit 1fcbd22431.
2019-01-21 20:28:36 +00:00
Dan Abramov fe2ecd276e
Add test coverage for readContext() on the server (#14649)
* Rename context variables

I just spent half an hour debugging why readContext(PurpleContext) doesn't work.

* Add test coverage for readContext() on the server
2019-01-21 19:55:26 +00:00
Dan Abramov 8f45a7fdc4
Warn about incorrect use of useImperativeHandle() (#14647) 2019-01-21 19:44:18 +00:00
Dan Abramov 1fcbd22431
Disallow reading context during useMemo etc (#14648)
* Disallow reading context during useMemo etc

* Continue allowing readContext() in classes and context consumers

The previous commit check was too broad and incorrectly restricted classes from calling readContext(). This check is more precise and only targets components that are Hook-capable. It exploits the fact that `renderExpirationTime` is never `NoWork` after `renderWithHooks` -- something we already rely on.
2019-01-21 19:06:09 +00:00
Dan Abramov 2a084f51a9
Warn about refs on lazy function components (#14645) 2019-01-21 16:57:55 +00:00
Linchengyi b5a3df6e88 Fix typo (#14560)
fix typo
2019-01-21 16:18:29 +00:00
liunian 9c146e6751 fix typo (#14316) 2019-01-21 16:18:02 +00:00
Dan Abramov baa6d40fc8
Mention forwardRef() in <Fn ref={...} /> errors and warnings (#14644) 2019-01-21 16:01:48 +00:00
Dan Abramov a1414e8949
Double-render function components with Hooks in DEV in StrictMode (#14643)
* Double-render functions in strict mode

* Double-invoke first function component render too

* Mark TestRendererAsync test as internal and revert changes to it

TestRenderer is built with strict mode doublerender off.

We could change that but I'm not sure we want to. So I'll just flip the flag off for this test.

* Only double-invoke components using Hooks

* Revert unintentional change
2019-01-21 15:35:47 +00:00
Dan Abramov 10a7a5b5ce
Fix synchronous thenable rejection (#14633)
* Fix handling of sync rejection

Reverts #14632 and adds a regression test.

* Handle rejection synchronously too

Fewer footguns and seems like nicer behavior anyway.
2019-01-19 00:42:43 +00:00
Dan Abramov a2fa6eb98d
Move lazy._result assignment (#14632) 2019-01-18 21:57:26 +00:00
Dan Abramov 9120f6c2d8
Support sync thenables for lazy() (#14626)
* Support sync thenables for lazy()

* Don't commit twice
2019-01-18 21:16:02 +00:00
Grey Baker b66e6e41e6 Add directory details to the package.json of all packages (#14628)
Specifying the directory as part of the `repository` field in a `package.json`
allows third party tools to provide better support when working with monorepos.
For example, it allows them to correctly construct a commit diff for a specific
package.

This format was accepted by npm in https://github.com/npm/rfcs/pull/19.
2019-01-18 20:21:12 +00:00
Brian Vaughn 8c1614a2fd
Tidy up NPM checkout process (#14631) 2019-01-18 11:40:50 -08:00
Dan Abramov 177fb76353
Warn when second callback is passed to setState/dispatch in Hooks (#14625) 2019-01-18 18:48:58 +00:00
Sebastian Silbermann d17d0b99c1 Use public context.report interface in eslint rules (#14623) 2019-01-18 09:26:11 +00:00
Yi-Shan, Chen 4f332885a2 Fix shallow renderer set instance state after gDSFP before calling sCU (#14613)
* Fix shallow renderer set instance state after gDSFP before calling sCU

* Update ReactShallowRenderer.js

* Unwind abstraction

* Fewer names
2019-01-18 02:31:14 +00:00
Sunil Pai e1cd83e49d
Throw an error when using hooks inside useMemo/useState/useReducer, or .memo's comparator (#14608)
* hooks inside useMemo/.memo - failing tests

* throw an error when using hooks inside useMemo

* throw when using hooks inside .memo's compare fn

* faster/better/stronger

* same logic for useReducer, tests for the server, etc

* Update ReactDOMServerIntegrationHooks-test.internal.js

ack lint

* nits

* whitespace

* whitespace

* stray semi

* Tweak comment

* stray unmatched fiber reset

* nit
2019-01-18 02:15:21 +00:00
Dan Abramov be457ca685
Small tweaks to SSR to match #14594 (#14618)
* Small tweaks to SSR to match #14594

* Remove unnecessary comparison
2019-01-18 00:52:13 +00:00
Dan Abramov 17d70df919
Warn when mixing createRoot() and old APIs (#14615)
* Warn when mixing createRoot() and old APIs

* Move container checks to entry points

This way further warning check doesn't crash on bad inputs.

* Fix Flow

* Rename flag to be clearer

* managed by -> passed to

* Revert accidental change

* Fix Fire shim to match
2019-01-18 00:20:21 +00:00
Brian Vaughn 4846809370
Prune NPM metadata fields from packages before re-publishing (#14617) 2019-01-17 14:34:34 -08:00
Dominic Gannaway 4feab7fc92
Add hooks support to ReactShallowRenderer (#14567)
* Add hook support to ReactShallowRenderer
2019-01-17 17:42:27 +00:00
Andrew Clark 1454a8be03
Don't bother comparing constructor when deps are not provided (#14594)
* Don't bother comparing constructor when deps are not provided

When no dependencies are passed to an effect hook, what we used to do is
compare the effect constructor. If there was no change, then we would
skip firing the effect. In practice, this is a useless optimization
because the constructor will always be different when you pass an inline
closure. And if you don't pass an inline closure, then you can't access
any props or state.

There are some edge cases where an effect that doesn't close over props
or state could be useful, like reference counting the number of mounted
components. But those are rare and can be addressed by passing an empty
array of dependencies.

By removing this "optimization," we can avoid retaining the constructor
in the majority of cases where it's a closure that changes on
every render.

I made corresponding changes to the other hooks that accept
dependencies, too (useMemo, useCallback, and useImperativeHandle).

* Improve hook dependencies warning

It now includes the name of the hook in the message.

* Nits
2019-01-16 17:53:48 -08:00
Andrew Clark 71b64d5211
Warn if number of hooks increases (#14591)
Eventually, we'll likely support adding hooks to the end (to enable
progressive enhancement), but let's warn until we figure out how it
should work.
2019-01-16 17:25:32 -08:00
Andrew Clark 790c8ef041
Allow useReducer to bail out of rendering by returning previous state (#14569)
* Allow useReducer to bail out of rendering by returning previous state

This is conceptually similar to `shouldComponentUpdate`, except because
there could be multiple useReducer (or useState) Hooks in a single
component, we can only bail out if none of the Hooks produce a new
value. We also can't bail out if any the other types of inputs — state
and context — have changed.

These optimizations rely on the constraint that components are pure
functions of props, state, and context.

In some cases, we can bail out without entering the render phase by
eagerly computing the next state and comparing it to the current one.
This only works if we are absolutely certain that the queue is empty at
the time of the update. In concurrent mode, this is difficult to
determine, because there could be multiple copies of the queue and we
don't know which one is current without doing lots of extra work, which
would defeat the purpose of the optimization. However, in our
implementation, there are at most only two copies of the queue, and if
*both* are empty then we know that the current queue must be.

* Add test for context consumers inside hidden subtree

Should not bail out during subsequent update. (This isn't directly
related to this PR because we should have had this test, anyway.)

* Refactor to use module-level variable instead of effect bit

* Add test combining state bailout and props bailout (memo)
2019-01-16 17:23:35 -08:00
Dan Abramov 8a120095bf
Add ESLint rule playground (#14609)
* Add ESLint rule playground

* Update index.js

* Update index.js
2019-01-16 23:52:33 +00:00
Brian Vaughn 7ab8a8e979
Added Flow type to keep hooks dispatchers in-sync (#14599)
* Added Flow type to keep hooks dispatchers in-sync
2019-01-16 12:49:31 -08:00
Brian Vaughn 4392e3821d
useDebugValue should throw if used in a class component (#14601) 2019-01-15 13:49:39 -08:00
Brian Vaughn 153a0b5980
Add noop useDebugValue hook to partial/server renderer (#14597) 2019-01-15 11:00:03 -08:00
Brian Vaughn 0ca628b216
Rename release script fixture test scheduler->tracing (#14590) 2019-01-14 17:52:03 -08:00
Brandon Dail 7ad9806d11
Tweak to avoid property read (#14593) 2019-01-14 17:39:27 -08:00
Brandon Dail 0fc1547513 Avoid new Set([iterable]) for thenables (#14592)
Fixes https://github.com/facebook/react/issues/14583

Using `new Set([iterable])` does not work with IE11's non-compliant Set
implementation. By avoiding this pattern we don't need to require a Set
polyfill for IE11
2019-01-15 01:00:15 +00:00
Brian Vaughn edb1f59564
Support configurable labels for custom hooks (#14559)
* react-debug-tools accepts currentDispatcher ref as param

* ReactDebugHooks injected dispatcher ref is optional

* Support custom values for custom hooks

* PR feedback:

1. Renamed useDebugValueLabel hook to useDebugValue
2. Wrapped useDebugValue internals in if-DEV so that it could be removed from production builds.

* PR feedback:

1. Fixed some minor typos
2. Added inline comment explaining the purpose of  rollupDebugValues()
3. Refactored rollupDebugValues() to use a for loop rather than filter()
4. Improve check for useDebugValue hook to lessen the chance of a false positive
5. Added optional formatter function param to useDebugValue

* Nitpick renamed a method
2019-01-14 14:53:22 -08:00
Sunil Pai 3e15b1c690
make a fork for ReactCurrentDispatcher (#14588) 2019-01-14 16:35:56 +00:00
Carl Mungazi 0005d1e3f5 Fix typo (#14576) 2019-01-11 21:46:05 -08:00
Brian Vaughn f290138d32
react-debug-tools accepts currentDispatcher ref as param (#14556)
* react-debug-tools accepts currentDispatcher ref as param

* ReactDebugHooks injected dispatcher ref is optional
2019-01-10 12:56:52 -08:00
Sunil Pai b4ad8e9471
rename useImperativeMethods -> useImperativeHandle (#14565) 2019-01-10 13:37:50 +00:00
Brian Vaughn ab03e3d651
Inject ReactCurrentDispatcher ref to DevTools (#14550) 2019-01-08 21:25:26 -08:00
Brian Vaughn 19ef0ec116
Separate current owner and dispatcher (#14548) 2019-01-08 14:39:52 -08:00
Maksim Markelov a9b035b0c2 Separate Object.is polyfill (#14334)
* Separate_Object_Is_Polyfill
2019-01-08 14:21:12 +00:00
Sophie Alpert 547e059f0b
Simplify wording of key warning (#14503)
I don't think "array or iterator" is adding anything, and it may well be confusing, especially since this is one of the first and most common warnings that devs see.
2019-01-07 08:30:23 -08:00
Carl Mungazi 3494ee57e6 Update ReactUpdateQueue.js (#14521)
Fix comment typo
2019-01-02 20:53:05 +00:00
Ilja Daderko fef40c061e Allow node 11 as devEngine (#14450)
Using node 11 throws incompatibility error. This fixes it. Only test I performed was to run `yarn build -- --type=RN_OSS` everything seemed ok.
2018-12-25 17:05:31 +00:00
Carl Mungazi 659c13963e Update ReactFiberScheduler.js (#14477)
Fixed typo
2018-12-20 08:51:47 -08:00
Andrew Clark 84b86471ea Update CHANGELOG for 16.7 2018-12-19 17:29:25 -08:00
Andrew Clark c695b2384f React v16.7.0 2018-12-19 17:23:14 -08:00