Skip to content

Bug: React 19 Uncaught TypeError: Do not know how to serialize a BigInt #35004

@nuintun

Description

@nuintun

React version: 19

Steps To Reproduce

  1. Set props with bigint
import { useCallback, useState } from 'react';

interface ServiceItem {
  name: string;
  regionIds: bigint[];
}

interface MachineItem {
  name: string;
  services: ServiceItem[];
}

interface MachineItemProps {
  machine: MachineItem;
}

function Machine(props: MachineItemProps) {
  return (
    <>
      <p>{props.machine.name}</p>
      {props.machine.services.map(service => (
        <p key={service.name}>{service.name}</p>
      ))}
    </>
  );
}

export default function Page() {
  const [update, setUpdate] = useState(0);
  const [machine, setMachine] = useState(() => {
    return {
      name: 'machine1',
      services: [
        {
          name: 'service1',
          regionIds: [31321968590458880n]
        }
      ]
    };
  });

  const onClick = useCallback(() => {
    setUpdate(update => ++update);

    setMachine(() => {
      return {
        name: 'machine2',
        services: [
          {
            name: 'service2',
            regionIds: [31321968590458881n]
          }
        ]
      };
    });
  }, []);

  return (
    <>
      <Machine machine={machine} />
      <button onClick={onClick}>Update {update}</button>
    </>
  );
}

Link to code example:

https://codesandbox.io/p/sandbox/pedantic-shirley-cg3nf8

The current behavior

Throw exception

Image

Image

The expected behavior

Do not throw exception

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions