mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
dc7eedae3c
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.
24 lines
647 B
JavaScript
24 lines
647 B
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow
|
|
*/
|
|
|
|
import {convertStringToBuffer} from 'react-server/src/ReactServerStreamConfig';
|
|
|
|
export function formatChunkAsString(type: string, props: Object): string {
|
|
let str = '<' + type + '>';
|
|
if (typeof props.children === 'string') {
|
|
str += props.children;
|
|
}
|
|
str += '</' + type + '>';
|
|
return str;
|
|
}
|
|
|
|
export function formatChunk(type: string, props: Object): Uint8Array {
|
|
return convertStringToBuffer(formatChunkAsString(type, props));
|
|
}
|