Skip to content

Commit

Permalink
Need to beat into Flow that bigint is a thing
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Jul 3, 2022
1 parent f9a7b6d commit a87598f
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 5 deletions.
6 changes: 5 additions & 1 deletion packages/react-dom/src/client/ReactDOMComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,11 @@ function setInitialDOMProperties(
if (canSetTextContent) {
setTextContent(domElement, nextProp);
}
} else if (typeof nextProp === 'number' || typeof nextProp === 'bigint') {
} else if (
typeof nextProp === 'number' ||
// $FlowFixMe - flow is not aware of `bigint`
typeof nextProp === 'bigint'
) {
setTextContent(domElement, '' + nextProp);
}
} else if (
Expand Down
6 changes: 5 additions & 1 deletion packages/react-dom/src/client/ReactDOMHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,13 @@ export function createInstance(
if (
typeof props.children === 'string' ||
typeof props.children === 'number' ||
// $FlowFixMe - flow is not aware of `bigint`
typeof props.children === 'bigint'
) {
const string = '' + props.children;
// Flow thinks `children` is still mixed so we need to type-cast
// But now the ESLint plugin thinks `children` is mixed as well.
// eslint-disable-next-line react-internal/safe-string-coercion
const string = '' + ((props.children: any): number | string);
const ownAncestorInfo = updatedAncestorInfo(
hostContextDev.ancestorInfo,
type,
Expand Down
7 changes: 6 additions & 1 deletion packages/react-dom/src/server/ReactPartialRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ function getNonChildrenInnerMarkup(props) {
if (
typeof content === 'string' ||
typeof content === 'number' ||
// $FlowFixMe - flow is not aware of `bigint`
typeof content === 'bigint'
) {
return escapeTextForBrowser(content);
Expand Down Expand Up @@ -1008,9 +1009,13 @@ class ReactDOMServerRenderer {
if (
typeof child === 'string' ||
typeof child === 'number' ||
// $FlowFixMe - flow is not aware of `bigint`
typeof child === 'bigint'
) {
const text = '' + child;
// Flow thinks `child` is still mixed so we need to type-cast
// But now the ESLint plugin thinks `children` is mixed as well.
// eslint-disable-next-line react-internal/safe-string-coercion
const text = '' + ((child: any): number | string);
if (text === '') {
return '';
}
Expand Down
4 changes: 4 additions & 0 deletions packages/react-reconciler/src/ReactChildFiber.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ function ChildReconciler(shouldTrackSideEffects) {
if (
(typeof newChild === 'string' && newChild !== '') ||
typeof newChild === 'number' ||
// $FlowFixMe - flow is not aware of `bigint`
typeof newChild === 'bigint'
) {
// Text nodes don't have keys. If the previous node is implicitly keyed
Expand Down Expand Up @@ -569,6 +570,7 @@ function ChildReconciler(shouldTrackSideEffects) {
if (
(typeof newChild === 'string' && newChild !== '') ||
typeof newChild === 'number' ||
// $FlowFixMe - flow is not aware of `bigint`
typeof newChild === 'bigint'
) {
// Text nodes don't have keys. If the previous node is implicitly keyed
Expand Down Expand Up @@ -633,6 +635,7 @@ function ChildReconciler(shouldTrackSideEffects) {
if (
(typeof newChild === 'string' && newChild !== '') ||
typeof newChild === 'number' ||
// $FlowFixMe - flow is not aware of `bigint`
typeof newChild === 'bigint'
) {
// Text nodes don't have keys, so we neither have to check the old nor
Expand Down Expand Up @@ -1325,6 +1328,7 @@ function ChildReconciler(shouldTrackSideEffects) {
if (
(typeof newChild === 'string' && newChild !== '') ||
typeof newChild === 'number' ||
// $FlowFixMe - flow is not aware of `bigint`
typeof newChild === 'bigint'
) {
return placeSingleChild(
Expand Down
4 changes: 4 additions & 0 deletions packages/react-reconciler/src/ReactChildFiber.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ function ChildReconciler(shouldTrackSideEffects) {
if (
(typeof newChild === 'string' && newChild !== '') ||
typeof newChild === 'number' ||
// $FlowFixMe - flow is not aware of `bigint`
typeof newChild === 'bigint'
) {
// Text nodes don't have keys. If the previous node is implicitly keyed
Expand Down Expand Up @@ -569,6 +570,7 @@ function ChildReconciler(shouldTrackSideEffects) {
if (
(typeof newChild === 'string' && newChild !== '') ||
typeof newChild === 'number' ||
// $FlowFixMe - flow is not aware of `bigint`
typeof newChild === 'bigint'
) {
// Text nodes don't have keys. If the previous node is implicitly keyed
Expand Down Expand Up @@ -633,6 +635,7 @@ function ChildReconciler(shouldTrackSideEffects) {
if (
(typeof newChild === 'string' && newChild !== '') ||
typeof newChild === 'number' ||
// $FlowFixMe - flow is not aware of `bigint`
typeof newChild === 'bigint'
) {
// Text nodes don't have keys, so we neither have to check the old nor
Expand Down Expand Up @@ -1325,6 +1328,7 @@ function ChildReconciler(shouldTrackSideEffects) {
if (
(typeof newChild === 'string' && newChild !== '') ||
typeof newChild === 'number' ||
// $FlowFixMe - flow is not aware of `bigint`
typeof newChild === 'bigint'
) {
return placeSingleChild(
Expand Down
11 changes: 9 additions & 2 deletions packages/react-server/src/ReactFizzServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1352,11 +1352,18 @@ function renderNodeDestructiveImpl(
return;
}

if (typeof node === 'number' || typeof node === 'bigint') {
if (
typeof node === 'number' ||
// $FlowFixMe - flow is not aware of `bigint`
typeof node === 'bigint'
) {
const segment = task.blockedSegment;
segment.lastPushedText = pushTextInstance(
task.blockedSegment.chunks,
'' + node,
// Flow thinks `children` is still mixed so we need to type-cast
// But now the ESLint plugin thinks `children` is mixed as well.
// eslint-disable-next-line react-internal/safe-string-coercion
'' + ((node: any): number),
request.responseState,
segment.lastPushedText,
);
Expand Down
1 change: 1 addition & 0 deletions packages/react-server/src/ReactFlightServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ export function resolveModelToJSON(
if (
typeof value === 'boolean' ||
typeof value === 'number' ||
// $FlowFixMe - flow is not aware of `bigint`
typeof value === 'bigint' ||
typeof value === 'undefined'
) {
Expand Down
1 change: 1 addition & 0 deletions packages/shared/ReactTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export type ReactFragment = ReactEmpty | Iterable<React$Node>;

export type ReactNodeList = ReactEmpty | React$Node;

// TODO: Add ` | bigint` once its supported by the used version of Flow.
export type ReactText = string | number;

export type ReactProvider<T> = {
Expand Down

0 comments on commit a87598f

Please sign in to comment.