From dc7eedae3c67f1b48db0bb1874633edf4268ac4e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Sebastian=20Markb=C3=A5ge?=
Date: Wed, 11 Mar 2020 09:48:02 -0700
Subject: [PATCH] Encode server rendered host components as array tuples
(#18273)
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 1fef79b182bef..e00e78dd48c5f 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 bb82a5e9a41cf..f0558215269c0 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: