From 47df380eba4b33f9d210461e8141631073f0e583 Mon Sep 17 00:00:00 2001
From: Sebastian Markbage
Date: Tue, 10 Mar 2020 22:31:30 -0700
Subject: [PATCH] Encode server rendered host components as array tuples
This replaces the HTML renderer with instead resolving host elements into
arrays tagged with the react.element symbol. These turn into proper
React Elements on the client.
The symbol is encoded as the magical value "$". This has security implications
so this special value needs to remain escaped for other strings.
We could just encode the element as {$$typeof: "$", key: key props: props}
but that's a lot more bytes. So instead I encode it as:
["$", key, props] and then convert it back.
It would be nicer if React's reconciler could just accept these tuples.
---
fixtures/flight-browser/index.html | 6 +-
fixtures/flight/server/handler.js | 4 +-
fixtures/flight/src/App.js | 2 +-
.../react-client/src/ReactFlightClient.js | 89 +++++++++++++++----
.../src/ReactFlightDOMRelayClient.js | 4 +-
.../src/__tests__/ReactFlightDOM-test.js | 43 ++++++++-
.../__tests__/ReactFlightDOMBrowser-test.js | 7 +-
.../src/ReactDOMServerFormatConfig.js | 12 ---
.../react-server/src/ReactFlightServer.js | 10 ++-
.../forks/ReactServerFormatConfig.custom.js | 2 -
10 files changed, 132 insertions(+), 47 deletions(-)
diff --git a/fixtures/flight-browser/index.html b/fixtures/flight-browser/index.html
index 1fef79b182b..e00e78dd48c 100644
--- a/fixtures/flight-browser/index.html
+++ b/fixtures/flight-browser/index.html
@@ -57,9 +57,7 @@ Flight Example
let model = {
title: ,
- content: {
- __html: ,
- }
+ content:
,
};
let stream = ReactFlightDOMServer.renderToReadableStream(model);
@@ -90,7 +88,7 @@ Flight Example
{model.title}
-
+ {model.content}
;
}
diff --git a/fixtures/flight/server/handler.js b/fixtures/flight/server/handler.js
index bb82a5e9a41..f0558215269 100644
--- a/fixtures/flight/server/handler.js
+++ b/fixtures/flight/server/handler.js
@@ -20,9 +20,7 @@ function HTML() {
module.exports = function(req, res) {
res.setHeader('Access-Control-Allow-Origin', '*');
let model = {
- content: {
- __html: