Remove unnecessary SSR warnings

This commit is contained in:
Aria Minaei 2022-12-13 18:10:32 +01:00
parent fcd3ab7ec5
commit 4e7f23ba8a
2 changed files with 24 additions and 17 deletions

View file

@ -113,15 +113,18 @@ export default class Project {
}
}, 0)
} else {
setTimeout(() => {
if (!this._studio) {
if (typeof window === 'undefined') {
console.warn(
if (process.env.NODE_ENV === 'production') {
console.error(
`Argument config.state in Theatre.getProject("${id}", config) is empty. ` +
`This is fine on SSR mode in development, but if you're creating a production bundle, make sure to set config.state, ` +
`You can safely ignore this message if you're developing a Next.js/Remix project in development mode. But if you are shipping to your end-users, ` +
`then you need to set config.state, ` +
`otherwise your project's state will be empty and nothing will animate. Learn more at https://www.theatrejs.com/docs/latest/manual/projects#state`,
)
}
} else {
setTimeout(() => {
if (!this._studio) {
throw new Error(
`Argument config.state in Theatre.getProject("${id}", config) is empty. This is fine ` +
`while you are using @theatre/core along with @theatre/studio. But since @theatre/studio ` +
@ -130,10 +133,10 @@ export default class Project {
`the project's state. Learn how to do that at https://www.theatrejs.com/docs/latest/manual/projects#state\n`,
)
}
}
}, 1000)
}
}
}
attachToStudio(studio: Studio) {
if (this._studio) {

View file

@ -99,6 +99,7 @@ export class Studio {
this.address = {studioId: nanoid(10)}
this.publicApi = new TheatreStudio(this)
// initialize UI if we're in the browser
if (process.env.NODE_ENV !== 'test' && typeof window !== 'undefined') {
this.ui = new UIConstructorModule.default(this)
}
@ -106,6 +107,8 @@ export class Studio {
this._attachToIncomingProjects()
this.paneManager = new PaneManager(this)
// check whether studio.initialize() is called, but only if we're in the browser
if (typeof window !== 'undefined') {
setTimeout(() => {
if (!this._initializeFnCalled) {
console.error(STUDIO_NOT_INITIALIZED_MESSAGE)
@ -113,6 +116,7 @@ export class Studio {
}
}, 100)
}
}
async initialize(opts?: Parameters<IStudio['initialize']>[0]) {
if (this._initializeFnCalled) {