remotion-dev / remotion

πŸŽ₯ Make videos programmatically with React
https://remotion.dev
Other
19.58k stars 952 forks source link

Inconsistent serialization between `render` and `studio` of the `calculateMetadata` result #4025

Open andrasferenczi opened 1 week ago

andrasferenczi commented 1 week ago

Bug Report πŸ›

I created the following composition:

    <Composition
      fps={30}
      id="NoSerializeComposition"
      height={720}
      width={1280}
      durationInFrames={10}
      calculateMetadata={() => {
        return {
          props: {
            calculated: new Vector2(10, 10),
          },
        }
      }}
      defaultProps={{
        calculated: undefined,
      }}
      component={({ calculated }: { calculated?: Vector2 }) => {
        const value = `${calculated}`

        console.log(value)

        return (
          <AbsoluteFill>
            <h1>{value}</h1>
          </AbsoluteFill>
        )
      }}
    />

export class Vector2 {
  readonly x: number
  readonly y: number

  constructor(x: number, y: number) {
    this.x = x
    this.y = y
  }

  toString(): string {
    return `Vector2 [X: ${this.x}, Y: ${this.y}]`
  }
}

Key points from this example:

I think this is a bug, because:

Is there a way to undo this serialization?

Thank you!

JonnyBurger commented 6 days ago

Thanks for reporting!

Objects are being passed between browser and Node.js and there is no useful way of undoing serialization of classes. We'll fix this by updating the docs to explicitly disallow non-JSON-serializable values.

JonnyBurger commented 6 days ago

To still improve it, in the next version the serialization will be consistent and in the Studio it will also turn into an object, to catch this earlier in the developer journey.

andrasferenczi commented 6 days ago

Makes sense, thanks. Based on your comments I got a better understanding of how Remotion works.

Couple minor doc comments I feel is missing from calculateMetadata is that: