mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
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.
This commit is contained in:
committed by
GitHub
parent
bf351089a0
commit
dc7eedae3c
@@ -9,8 +9,6 @@
|
||||
|
||||
import {convertStringToBuffer} from 'react-server/src/ReactServerStreamConfig';
|
||||
|
||||
import {renderToStaticMarkup} from 'react-dom/server';
|
||||
|
||||
export function formatChunkAsString(type: string, props: Object): string {
|
||||
let str = '<' + type + '>';
|
||||
if (typeof props.children === 'string') {
|
||||
@@ -23,13 +21,3 @@ export function formatChunkAsString(type: string, props: Object): string {
|
||||
export function formatChunk(type: string, props: Object): Uint8Array {
|
||||
return convertStringToBuffer(formatChunkAsString(type, props));
|
||||
}
|
||||
|
||||
export function renderHostChildrenToString(
|
||||
children: React$Element<any>,
|
||||
): string {
|
||||
// TODO: This file is used to actually implement a server renderer
|
||||
// so we can't actually reference the renderer here. Instead, we
|
||||
// should replace this method with a reference to Fizz which
|
||||
// then uses this file to implement the server renderer.
|
||||
return renderToStaticMarkup(children);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user