Commit Graph
95 Commits
Author SHA1 Message Date
Andrew ClarkandGitHub 4756f74405 Wire up the native API for useSyncExternalStore (#22237)
Adds useSyncExternalStore to the internal dispatcher, and exports
the native API from the React package without yet implementing it.
2021-09-07 10:20:24 -07:00
Sebastian MarkbågeandGitHub 1ba2eed72b [Fizz] Don't add aborted segments to the completedSegments list (#21976)
* Don't add aborted segments to the completedSegments list

* Update error message to include aborted status
2021-07-27 21:53:37 -04:00
Deniz SusmanandGitHub b7cc61cb88 Typo fix (#21729)
emitted instead of emmitted
2021-07-19 17:19:52 -04:00
RickyandGitHub addb77d656 Allow components to render undefined (#21869) 2021-07-13 15:48:11 -04:00
Sebastian MarkbågeandGitHub 955ae55529 [Fizz/Flight] Don't use default args (#21681)
* Don't use default args

* Hoist out creation for better inlining

The closures prevent inlining otherwise.
2021-06-14 15:28:20 -07:00
Sebastian MarkbågeandGitHub b0ad75edf9 [Fizz] Implement Legacy renderToString and renderToNodeStream on top of Fizz (#21276)
* Wire up DOM legacy build

* Hack to filter extra comments for testing purposes

* Use string concat in renderToString

I think this might be faster. We could probably use a combination of this
technique in the stream too to lower the overhead.

* Error if we can't complete the root synchronously

Maybe this should always error but in the async forms we can just delay
the stream until it resolves so it does have some useful semantics.

In the synchronous form it's never useful though. I'm mostly adding the
error because we're testing this behavior for renderToString specifically.

* Gate memory leak tests of internals

These tests don't translate as is to the new implementation and have been
ported to the Fizz tests separately.

* Enable Fizz legacy mode in stable

* Add wrapper around the ServerFormatConfig for legacy mode

This ensures that we can inject custom overrides without negatively
affecting the new implementation.

This adds another field for static mark up for example.

* Wrap pushTextInstance to avoid emitting comments for text in static markup

* Don't emit static mark up for completed suspense boundaries

Completed and client rendered boundaries are only marked for the client
to take over.

Pending boundaries are still supported in case you stream non-hydratable
mark up.

* Wire up generateStaticMarkup to static API entry points

* Mark as renderer for stable

This shouldn't affect the FB one ideally but it's done with the same build
so let's hope this works.
2021-06-14 12:54:30 -07:00
Dan AbramovandGitHub 6a7d01793d [Fizz] Always call flush() if it exists (#21625) 2021-06-04 20:17:57 +01:00
Sebastian MarkbågeandGitHub 95e03035a5 [Fizz] Minor Fixes for Warning Parity (#21618) 2021-06-03 19:54:31 -04:00
Sebastian MarkbågeandGitHub 7700052898 [Fizz] Implement Component Stacks in DEV for warnings (#21610)
* Implement component stacks

This uses a reverse linked list in DEV-only to keep track of where we're
currently executing.

* Fix bug that wasn't picking up the right stack at suspended boundaries

This makes it more explicit which stack we pass in to be retained by the
task.
2021-06-03 13:02:41 -07:00
Sebastian MarkbågeandGitHub 9b8c939ca6 Switch the isPrimaryRender flag based on the stream config (#21357) 2021-04-26 22:37:05 -04:00
Sebastian MarkbågeandGitHub f6585c843a [Fizz] Implement lazy components and nodes (#21355)
* Implement lazy components

* Implement lazy elements / nodes

This is used by Flight to encode not yet resolved nodes of any kind.
2021-04-26 18:46:46 -07:00
Sebastian MarkbågeandGitHub 4e06ed214e Restore context after an error happens (#21341)
Typically we don't need to restore the context here because we assume that
we'll terminate the rest of the subtree so we don't need the correct
context since we're not rendering any siblings.

However, after a nested suspense boundary we need to restore the context.
The boundary could do this but since we're already doing this in the
suspense branch of renderNode, we might as well do it in the error case
which isn't very perf sensitive anyway.
2021-04-23 12:24:10 -07:00
Sebastian MarkbågeandGitHub 4bbc0e3548 [Fizz] Add FB specific streaming API and build (#21337)
Add FB specific streaming API and build
2021-04-22 16:54:29 -07:00
RickyandGitHub e305b111a5 Flip tuple order of useTransition (#20976) 2021-04-20 12:21:44 -04:00
Sebastian MarkbågeandGitHub 25ee357cb2 Mark boundary as client rendered even if aborting fallback (#21294) 2021-04-15 19:16:40 -04:00
Sebastian MarkbågeandGitHub 83d4aefe2d [Fizz] Two More Fixes (#21288)
* Emit value of option tags

* Mask the legacy context passed to classes
2021-04-15 10:26:49 -07:00
Sebastian MarkbågeandGitHub bfeebcc862 Fix classes (#21283) 2021-04-15 08:06:31 -07:00
Sebastian MarkbågeandGitHub 1fd681e4cd [Fizz] Random Fixes (#21277) 2021-04-14 23:29:30 -04:00
Sebastian MarkbågeandGitHub 7f2b741443 Always insert a dummy node with an ID into fallbacks (#21272) 2021-04-14 15:39:51 -07:00
Sebastian MarkbågeandGitHub 84f5c6b767 [Fizz] Add unsupported Portal/Scope components (#21261)
* Update Portal error message

* Add Scope Component
2021-04-14 14:35:36 -07:00
Sebastian MarkbågeandGitHub 36ad2f8d09 Implement useOpaqueIdentifier (#21260)
The format of this ID is specific to the format.
2021-04-14 14:25:42 -07:00
Sebastian MarkbågeandGitHub 589cd04a3c [Fizz] Implement Hooks (#21257)
* Implement Fizz Hooks

This is pretty much just a copy of the partial renderer Hooks.

* Implement forward ref and memo
2021-04-14 14:16:41 -07:00
Sebastian MarkbågeandGitHub 56cfb43dba [Fizz] Fix reentrancy bug (#21270)
* Fix reentrancy bug

* Fix another reentrancy bug

There's also an issue if we try to schedule something to be client
rendered if its fallback hasn't rendered yet. So we don't do it
in that case.
2021-04-14 13:49:14 -07:00
Sebastian MarkbågeandGitHub c38a04fe64 [Fizz] Implement New Context (#21255)
* Add NewContext module

This implements a reverse linked list tree containing the previous
contexts.

* Implement recursive algorithm

This algorithm pops the contexts back to a shared ancestor on the way down
the stack and then pushes new contexts in reverse order up the stack.

* Move isPrimaryRenderer to ServerFormatConfig

This is primarily intended to be used to support renderToString with a
separate build than the main one. This allows them to be nested.

* Wire up more element type matchers

* Wire up Context Provider type

* Wire up Context Consumer

* Test

* Implement reader in class

* Update error codez
2021-04-14 11:45:42 -07:00
Sebastian MarkbågeandGitHub 00b6750584 [Fizz] Classes Follow Up (#21253)
* Port Classes from Fiber to Fizz

* Test
2021-04-13 13:57:36 -07:00
Sebastian MarkbågeandGitHub 2eee3c4153 [Fizz] Fragments and Iterable support (#21228) 2021-04-10 15:50:42 -04:00
Sebastian MarkbågeandGitHub 74ef65b1ff Support more empty types (#21225)
Undefined errors as a direct return value.

This changes semantics for "true" and functions to mirror the client.
2021-04-09 16:23:37 -07:00
Sebastian MarkbågeandGitHub 558cb234a7 [Fizz] Implement Classes (#21200)
* Legacy context

* Port Classes from Fiber to Fizz
2021-04-08 10:42:37 -07:00
Sebastian MarkbågeandGitHub 2a8e7eb2a7 [Fizz] Prepare Recursive Loop for More Types (#21186)
* Split out into helper functions

This is similar to the structure of beginWork in Fiber.

* Split the rendering of a node from recursively rendering a node

This lets us reuse render node at the root which doesn't spawn new work.
2021-04-07 11:29:06 -07:00
8d1611f658 Reland Remove redundant initial of isArray (#21188)
* Remove redundant initial of isArray (#21163)

* Reapply prettier

* Type the isArray function with refinement support

This ensures that an argument gets refined just like it does if isArray is
used directly.

I'm not sure how to express with just a direct reference so I added a
function wrapper and confirmed that this does get inlined properly by
closure compiler.

* A few more

* Rename unit test to internal

This is not testing a bundle.

Co-authored-by: Behnam Mohammadi <[email protected]>
2021-04-07 07:57:43 -07:00
Sebastian Markbage e92c1c329d Revert "Remove redundant initial of isArray (#21163)"
This reverts commit 619546c554.
2021-04-01 15:19:00 -04:00
Behnam MohammadiandGitHub 619546c554 Remove redundant initial of isArray (#21163) 2021-04-01 10:50:48 -07:00
Sebastian MarkbågeandGitHub 17d66afce9 Don't pass internals to callbacks (#21161)
I noticed that I accidentally pass the request object to public API callbacks
as "this".
2021-04-01 08:43:12 -07:00
Sebastian MarkbågeandGitHub b4ddd5b90c [Fizz] Implement all the DOM attributes and special cases (#21153)
* Implement DOM format config structure

* Styles

* Input warnings

* Textarea special cases

* Select special cases

* Option special cases

We read the currently selected value from the FormatContext.

* Warning for non-lower case HTML

We don't change to lower case at runtime anymore but keep the warning.

* Pre tags innerHTML needs to be prefixed

This is because if you do the equivalent on the client using innerHTML,
this is the effect you'd get.

* Extract errors
2021-03-31 17:39:38 -07:00
Sebastian MarkbågeandGitHub abb8950878 Log all errors to console.error by default (#21130) 2021-03-29 19:39:55 -07:00
Sebastian MarkbågeandGitHub c9f2f5099b [Flight] Add global onError handler (#21129)
* Add onError option to Flight Server

The callback is called any time an error is generated in a server component.

This allows it to be logged on a server if needed. It'll still be rethrown
on the client so it can be logged there too but in case it never reaches
the client, here's a way to make sure it doesn't get lost.

* Add fatal error handling
2021-03-29 19:36:16 -07:00
Sebastian MarkbågeandGitHub 6c85bd8754 [Fizz] Support special HTML/SVG/MathML tags to suspend (#21113)
* Encode tables as a special insertion mode

The table modes are special in that its children can't be created outside
a table context so we need the segment container to be wrapped in a table.

* Move formatContext from Task to Segment

It works the same otherwise. It's just that this context needs to outlive
the task so that I can use it when writing the segment.

* Use template tag for placeholders and inserted dummy nodes with IDs

These can be used in any parent. At least outside IE11. Not sure yet what
happens in IE11 to these.

Not sure if these are bad for perf since they're special nodes.

* Add special wrappers around inserted segments depending on their insertion mode

* Allow the root namespace to be configured

This allows us to insert the correct wrappers when streaming into an
existing non-HTML tree.

* Add comment
2021-03-27 10:50:38 -07:00
Sebastian MarkbågeandGitHub 525906e961 Fix plurals (#21106) 2021-03-25 22:21:41 -04:00
Sebastian MarkbågeandGitHub 254ca078d2 Rename SuspendedWork to Task (#21105) 2021-03-25 18:39:59 -07:00
Sebastian MarkbågeandGitHub db7d7f645c [Fizz] Add FormatContext and Refactor Work (#21103)
* Add format context

* Let the Work node hold all working state for the recursive loop

Stacks are nice and all but there's a cost to maintaining each frame
both in terms of stack size usage and writing to it.

* Move current format context into work

* Synchronously render children of a Suspense boundary

We don't have to spawn work and snapshot the context. Instead we can try
to render the boundary immediately in case it works.

* Lazily create the fallback work

Instead of eagerly create the fallback work and then immediately abort it.
We can just avoid creating it if we finish synchronously.
2021-03-25 18:38:43 -07:00
Sebastian MarkbågeandGitHub c799afb8e0 [Fizz] Expose callbacks in options for when various stages of the content is done (#21056)
* Report errors to a global handler

This allows you to log errors or set things like status codes.

* Add complete callback

* onReadyToStream callback

This is typically not needed because if you want to stream when the
root is ready you can just start writing immediately.

* Rename onComplete -> onCompleteAll
2021-03-23 11:39:38 -07:00
Sebastian MarkbågeandGitHub f2bcf5b72a Remove already completed comment (#21054) 2021-03-22 15:41:22 -07:00
Sebastian MarkbågeandGitHub 76fcee2ef7 [Fizz] Use identifierPrefix to avoid conflicts within the same response (#21037)
* Use identifierPrefix to avoid conflicts within the same response

identifierPrefix as an option exists to avoid useOpaqueIdentifier conflicting
when different renders are used within one HTML response.

This lets this be configured for the DOM renderer specifically since it's DOM
specific whether they will conflict across trees or not.

* Add test for using multiple containers in one HTML document
2021-03-22 13:10:57 -07:00
Sebastian MarkbågeandGitHub 8c39f0612f [Fizz] Expose maxBoundarySize as an option (#21029)
* Expose maxBoundarySize as an option

* Adjust the heuristic

* Rename to progressiveChunkSize
2021-03-19 09:41:25 -07:00
Sebastian MarkbågeandGitHub 6d0c8582d0 [Fizz] Expose a method to explicitly start writing to a Node stream (#21028)
* Expose an explicit point when to start writing in the Node API

* Add a previously failing test
2021-03-18 12:43:40 -07:00
Sebastian MarkbågeandGitHub c8fceee5e7 [Fizz] Expose a method to abort a pending request (#21027)
* Track all suspended work while it's still pending

This allows us to abort work and put everything into client rendered mode
if we don't want to wait for further I/O.

It also allows us to cancel fallbacks if we complete the main content
before the fallback.

* Expose abort API to the browser streams

Since this API already returns a value, we need to use destructuring to
expose more options.

* Add a test including the client actually client rendering it

* Use AbortSignal option for W3C streams instead of external control

* Clean up listener after it's used once
2021-03-18 09:46:15 -07:00
Sebastian MarkbågeandGitHub 2952be860c [Fizz] Assign an ID to the first DOM element in a fallback or insert a dummy (and testing infra) (#21020)
* Patches

* Add Fizz testing infra structure

* Assign an ID to the first DOM node in a fallback or insert a dummy

* unstable_createRoot
2021-03-16 14:05:52 -07:00
Sebastian MarkbågeandGitHub ca19f16f78 Allow the streaming config to decide how to precompute or compute chunks (#21008)
Some legacy environments can not encode non-strings. Those would specify
both as strings. They'll throw for binary data.

Some environments have to encode strings (like web streams). Those would
encode both as uint8array.

Some environments (like Node) can do either. It can be beneficial to leave
things as strings in case the native stream can do something smart with it.
2021-03-15 10:36:23 -07:00
Sebastian MarkbågeandGitHub 4fddd405be [Fizz] Move DOM/Native format configs to their respective packages (#20994)
* Move DOM/Native format configs to their respective packages

The streaming configs (Node/Browser) are different because they operate at
another dimension that exists in each package.

* Use escapeTextForBrowser to encode dynamic strings

We can now use local dependencies
2021-03-13 06:54:59 -08:00
Sebastian MarkbågeandGitHub a3d71ea21b [Fizz] Destroy the stream with an error if the root throws (#20992)
* Destroy the stream with an error if the root throws

But not if the error happens inside a suspense boundary.

* Try rewriting the test to see if it works in other Node envs
2021-03-12 15:21:02 -08:00