theatre-js / theatre

Motion design editor for the web
https://www.theatrejs.com
Apache License 2.0
10.86k stars 338 forks source link

Need a helpful warning if studio is imported but no initialized #21

Open AriaMinaei opened 2 years ago

AriaMinaei commented 2 years ago

Since tree-shaking in different build systems is not bullet proof, there are situations where the user intends for @theatre/studio to not be included in the bundle but it still ends up in there. We can help the user avoid this situation by emitting a warning if the studio is imported but studio.initialize() is not called within a time period.

Thanks @RuiOrey for the report :)

RuiOrey commented 2 years ago

You're welcome @AriaMinaei ! Anyways, even if it is imported without being initialized, should it not impact the loading and play of sequences, right? Seems there is some sort of code that is executed that breaks loading a json file and playing it.

AriaMinaei commented 2 years ago

Well if studio is present, all state loading is deferred to it. Otherwise, we'll have a situation where the state jumps from one that is provided to core, to one that studio has saved in localStorage.

RuiOrey commented 2 years ago

But shouldn't that only happen if we call studio.initialize() ?

AriaMinaei commented 2 years ago

I see what you mean. The word "initialize" implies that, if not called, then it shouldn't affect anything. So @theatre/core would work as if @theatre/studio is not present.

The reason it doesn't work that way is that there is no use in having @theatre/studio in the bundle if it isn't initialized. The reason I implemented initialize() was to give us a chance to configure the studio before it renders. So, if the studio is in the bundle but not initialized, then it's just taking up bundle space.

That's why I thought it's better to just warn the user if they're not calling initialize() right away.

loklaan commented 1 year ago

@AriaMinaei this looks to be closed by this commit.