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) }, 0)
} else { } else {
setTimeout(() => { if (typeof window === 'undefined') {
if (!this._studio) { if (process.env.NODE_ENV === 'production') {
if (typeof window === 'undefined') { console.error(
console.warn( `Argument config.state in Theatre.getProject("${id}", config) is empty. ` +
`Argument config.state in Theatre.getProject("${id}", config) is empty. ` + `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, ` +
`This is fine on SSR mode in development, but if you're creating a production bundle, make sure to set config.state, ` + `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`, `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 { }
} else {
setTimeout(() => {
if (!this._studio) {
throw new Error( throw new Error(
`Argument config.state in Theatre.getProject("${id}", config) is empty. This is fine ` + `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 ` + `while you are using @theatre/core along with @theatre/studio. But since @theatre/studio ` +
@ -130,8 +133,8 @@ export default class Project {
`the project's state. Learn how to do that at https://www.theatrejs.com/docs/latest/manual/projects#state\n`, `the project's state. Learn how to do that at https://www.theatrejs.com/docs/latest/manual/projects#state\n`,
) )
} }
} }, 1000)
}, 1000) }
} }
} }

View file

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