Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
andrasferenczi opened this issue Jun 22, 2024 · 3 comments 路 Fixed by #4034
Open
Labels
bug Something isn't working

Comments

@andrasferenczi
Copy link

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:

  • The calculateMetadata returns a non-serializable class, Vector2
  • The studio displays the following string: Vector2 [X: 10, Y: 10]
  • The render displays the following string: [object Object], which means it is no longer the Vector2 class

I think this is a bug, because:

Is there a way to undo this serialization?

Thank you!

@andrasferenczi andrasferenczi added the bug Something isn't working label Jun 22, 2024
@JonnyBurger
Copy link
Member

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
Copy link
Member

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
Copy link
Author

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:

  • it runs a single time, independent of the worker count (or concurrency defined in renderMedia)
  • it runs in a separate node process when rendering, executed whenever selectComposition is called

@JonnyBurger JonnyBurger reopened this Jun 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants