Commit Graph

10744 Commits

Author SHA1 Message Date
Brian Vaughn aa9423701e Tweaked publish canary message to show newly published version 2019-02-06 18:24:51 +00:00
Brian Vaughn 45fc46bfa0 16.8.1 packages 2019-02-06 18:21:33 +00:00
Dan Abramov b7cc6b2e6f
Add 16.8.1 changelog 2019-02-06 18:19:35 +00:00
Brian Vaughn f2e2637c8e
Backwards compat fix for ReactCurrentDispatcher on older react versions (#14770)
* Add current owner ref fallback for newer renderers with older react versions
* Replaced current owner forward with current:null
2019-02-06 17:02:14 +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
Brian Vaughn 0975ea3278 eslint-plugin-react-hooks v1.0.0 2019-02-06 10:14:57 +00:00
Dan Abramov d827445a50 Add 16.8.0 changelog and update some READMEs (#14692)
* Add 16.8.0 changelog

* Mention ESLint plugin

* Remove experimental notices from the ESLint plugin README

* Update CHANGELOG.md

* Add more details for Hooks

* fix

* Set a date

* Update CHANGELOG.md

Co-Authored-By: gaearon <dan.abramov@gmail.com>

* Update CHANGELOG.md

* useReducer in changelog

* Add to changelog

* Update date

* Add #14119 to changelog

* Add #14744 to changelog

* Fix PR links

* act() method was added to test utils, too

* Updated release date to February 6th
2019-02-06 08:31:00 +00:00
Andrew Clark bc9818f24d
Scheduler.unstable_next (#14756)
* Add Scheduler.unstable_next

* Use Scheduler to prioritize updates

Changes the implementation of syncUpdates, deferredUpdates, and
interactiveUpdates to use runWithPriority, so

This is the minimum integration between Scheduler and React needed to
unblock use of the Scheduler.next API.

* Add Scheduler.unstable_next

* Use Scheduler to prioritize updates

Changes the implementation of syncUpdates, deferredUpdates, and
interactiveUpdates to use runWithPriority, so

This is the minimum integration between Scheduler and React needed to
unblock use of the Scheduler.next API.
2019-02-06 08:16:41 +00:00
Dan Abramov b5398a9130 Add 16.8.0 changelog and update some READMEs (#14692)
* Add 16.8.0 changelog

* Mention ESLint plugin

* Remove experimental notices from the ESLint plugin README

* Update CHANGELOG.md

* Add more details for Hooks

* fix

* Set a date

* Update CHANGELOG.md

Co-Authored-By: gaearon <dan.abramov@gmail.com>

* Update CHANGELOG.md

* useReducer in changelog

* Add to changelog

* Update date

* Add #14119 to changelog

* Add #14744 to changelog

* Fix PR links

* act() method was added to test utils, too

* Updated release date to February 6th
2019-02-06 08:05:54 +00:00
Dan Abramov ce6ecd3fbf Add 16.8.0 changelog and update some READMEs (#14692)
* Add 16.8.0 changelog

* Mention ESLint plugin

* Remove experimental notices from the ESLint plugin README

* Update CHANGELOG.md

* Add more details for Hooks

* fix

* Set a date

* Update CHANGELOG.md

Co-Authored-By: gaearon <dan.abramov@gmail.com>

* Update CHANGELOG.md

* useReducer in changelog

* Add to changelog

* Update date

* Add #14119 to changelog

* Add #14744 to changelog

* Fix PR links

* act() method was added to test utils, too

* Updated release date to February 6th
2019-02-06 08:05:18 +00:00
Brian Vaughn 008a2ab9cd 16.8.0 2019-02-06 08:04:00 +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 81470a0027
Add missing 16.6.1 changelog entry 2019-02-04 13:28:26 +00:00
Jessica Franco e602b5291c Use SameValue instead of === to check for dispatchAction equivalence (#14752) 2019-02-04 04:56:21 -08:00
SToneX e489c3f9c1 Update the version with Hooks proposal in README (#14751) 2019-02-04 09:36:56 +00:00
Dan Abramov c21c41ecfa
Tweak invalid Hook warning and error (#14747) 2019-02-01 21:05:13 +00:00
Deniz Susman fec00a869c Typo in comment (#14739)
"synchronously" instead of "syncrhonously".
2019-02-01 13:26:24 +01: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 70d4075832
Move Hook mismatch warning to first mismatch site (#14720)
* Move Hook mismatch warning to first mismatch site

Allows us to localize the warning logic in one place.

* Nit
2019-01-30 08:11:18 -08: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
Peter Donald 9d483dcfd6 Spelling abitrarily -> arbitrarily (#14710) 2019-01-27 14:54:37 +00:00
DeepCold 6d5ea54eee change codeofconduct link (#14711) 2019-01-27 14:54:21 +00:00
Yurick e19c9e1064 Fix issue with multiple code branches in hooks linter (#14661)
* Fix issue with multiple code branches

* Add solution by @calebmer

* Add performance test

* Undo unrelated change
2019-01-25 17:06:33 +00: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
Greg Hurrell e679a4b6e2 Fix typo in code comment (#14696) 2019-01-24 20:19:53 +00:00
Dan Abramov 8bcc88f2e7
Make all readContext() and Hook-in-a-Hook checks DEV-only (#14677)
* Make readContext() in Hooks DEV-only warning

* Warn about readContext() during class render-phase setState()

* Warn on readContext() in SSR inside useMemo and useReducer

* Make all Hooks-in-Hooks warnings DEV-only

* Rename stashContextDependencies

* Clean up warning state on errors
2019-01-24 19:31:20 +00:00
Brian Vaughn 6cb26774e2
Enable hooks! (#14679)
* Turned enableHooks feature flag on everywhere
* Removed useHooks feature flag from tests (now that it's on by default)
* Remove useHooks feature flag entirely
2019-01-23 13:28:09 -08:00
Dan Abramov 73962c3664
Revert "Revert "Double-render function components with Hooks in DEV in StrictMode" (#14652)" (#14654)
This reverts commit 3fbebb2a0b.
2019-01-23 19:12:18 +00:00
Dan Abramov 9944392285
Put DEV-only code into DEV blocks (#14673) 2019-01-23 16:59:55 +00:00
Dan Abramov f0befae657
Tweak context invariant message (#14671) 2019-01-23 16:14:32 +00:00
Dan Abramov a129259ad6
Disallow reading context during useMemo etc (#14653)
* Revert "Revert "Double-render function components with Hooks in DEV in StrictMode" (#14652)"

This reverts commit 3fbebb2a0b.

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

This reverts commit 5fce6488ce.

* Add extra passing test for an edge case

Mentioned by @acdlite to watch out for

* More convoluted test

* Don't rely on expirationTime

Addresses @acdlite's concerns

* Edge case: forbid readContext() during eager reducer
2019-01-23 15:51:57 +00:00
Sebastian Markbåge c068d31cca Add unit tests for concurrent mode event dispatching (#14415) 2019-01-23 15:28:19 +00:00
Dan Abramov db695c4d32
Bump GCC (#14657) 2019-01-23 14:28:03 +00:00
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