react/scripts/error-codes
Sebastian Markbåge b52a5624e9 [CS] Persistent Updates (#11260)
* Update build size

* [CS] Clone container instead of new root concept

The extra "root" concept is kind of unnecessary. Instead of having a
mutable container even in the persistent mode, I'll instead make the
container be immutable too and be cloned. Then the "commit" just becomes
swapping the previous container for the new one.

* Change the signature or persistence again

We may need to clone without any updates, e.g. when the children are changed.

Passing in the previous node is not enough to recycle since it won't have the
up-to-date props and children. It's really only useful to for allocation pooling.

* Implement persistent updates

This forks the update path for host fibers. For mutation mode we mark
them as having an effect. For persistence mode, we clone the stateNode with
new props/children.

Next I'll do HostRoot and HostPortal.

* Refine protocol into a complete and commit phase

finalizeContainerChildren will get called at the complete phase.
replaceContainer will get called at commit.

Also, drop the keepChildren flag. We'll never keep children as we'll never
update a container if none of the children has changed.

* Implement persistent updates of roots and portals

These are both "containers". Normally we rely on placement/deletion effects
to deal with insertions into the containers. In the persistent mode we need
to clone the container and append all the changed children to it.

I needed somewhere to store these new containers before they're committed
so I added another field.

* Commit persistent work at the end by swapping out the container

* Unify cloneOrRecycle

Originally I tried to make the recyclable instance nullable but Flow didn't
like that and it's kind of sketchy since the instance type might not be
nullable.

However, the real difference which one we call is depending on whether they
are equal. We can just offload that to the renderer. Most of them won't
need to know about this at all since they'll always clone or just create
new.

The ones that do know now have to be careful to compare them so they don't
reuse an existing instance but that's probably fine to simplify the
implementation and API.

* Add persistent noop renderer for testing

* Add basic persistent tree test

* Test bail out

This adds a test for bailouts. This revealed a subtle bug. We don't set the
return pointer when stepping into newly created fibers because there
can only be one. However, since I'm reusing this mechanism for persistent
updates, I'll need to set the return pointer because a bailed out tree
won't have the right return pointer.

* Test persistent text nodes

Found another bug.

* Add persistent portal test

This creates a bit of an unfortunate feature testing in the unmount
branch.

That's because we want to trigger nested host deletions in portals in the
mutation mode.

* Don't consider container when determining portal identity

Basically, we can't use the container to determine if we should keep
identity and update an existing portal instead of recreate it. Because
for persistent containers, there is no permanent identity.

This makes it kind of strange to even use portals in this mode. It's
probably more ideal to have another concept that has permanent identity
rather than trying to swap out containers.

* Clear portals when the portal is deleted

When a portal gets deleted we need to create a new empty container and
replace the current one with the empty one.

* Add renderer mode flags for dead code elimination

* Simplify ReactNoop fix

* Add new type to the host config for persistent configs

We need container to stay as the persistent identity of the root atom.
So that we can refer to portals over time.

Instead, I'll introduce a new type just to temporarily hold the children
of a container until they're ready to be committed into the permanent
container. Essentially, this is just a fancy array that is not an array
so that the host can choose data structure/allocation for it.

* Implement new hooks

Now containers are singletons and instead their children swap. That way
portals can use the container as part of their identity again.

* Update build size and error codes

* Address comment

* Move new files to new location
2017-10-18 18:28:23 -07:00
..
__tests__ Update license headers BSD+Patents -> MIT 2017-09-25 18:17:44 -07:00
codes.json [CS] Persistent Updates (#11260) 2017-10-18 18:28:23 -07:00
extract-errors.js Update license headers BSD+Patents -> MIT 2017-09-25 18:17:44 -07:00
invertObject.js Update license headers BSD+Patents -> MIT 2017-09-25 18:17:44 -07:00
README.md [Gatsby] "https://facebook.github.io/react/" -> "https://reactjs.org/" (#10970) 2017-09-29 18:43:22 -07:00
replace-invariant-error-codes.js Update license headers BSD+Patents -> MIT 2017-09-25 18:17:44 -07:00
Types.js Update license headers BSD+Patents -> MIT 2017-09-25 18:17:44 -07:00

The error code system substitutes React's invariant error messages with error IDs to provide a better debugging support in production. Check out the blog post here.

Note for cutting a new React release

  1. For each release, we run yarn build -- --extract-errors to update the error codes before calling yarn build. The build step uses codes.json for a production (minified) build; there should be no warning like Error message "foo" cannot be found for a successful release.
  2. The updated codes.json file should be synced back to the master branch. The error decoder page in our documentation site uses codes.json from master; if the json file has been updated, the docs site should also be rebuilt (rake copy_error_codes is included in the default rake release task).
  3. Be certain to run yarn build -- --extract-errors directly in the release branch (if not master) to ensure the correct error codes are generated. These error messages might be changed/removed before cutting a new release, and we don't want to add intermediate/temporary error messages to codes.json. However, if a PR changes an existing error message and there's a specific production test (which is rare), it's ok to update codes.json for that. Please use yarn build -- --extract-errors and don't edit the file manually.

Structure

The error code system consists of 5 parts:

  • codes.json contains the mapping from IDs to error messages. This file is generated by the Gulp plugin and is used by both the Babel plugin and the error decoder page in our documentation. This file is append-only, which means an existing code in the file will never be changed/removed.
  • extract-errors.js is an node script that traverses our codebase and updates codes.json. Use it by calling yarn build -- --extract-errors.
  • replace-invariant-error-codes.js is a Babel pass that rewrites error messages to IDs for a production (minified) build.
  • reactProdInvariant.js is the replacement for invariant in production. This file gets imported by the Babel plugin and should not be used manually.
  • ErrorDecoderComponent is a React component that lives at https://reactjs.org/docs/error-decoder.html. This page takes parameters like ?invariant=109&args[]=Foo and displays a corresponding error message. Our documentation site's Rakefile has a task (bundle exec rake copy_error_codes) for adding the latest codes.json to the error decoder page. This task is included in the default bundle exec rake release task.