From 4e7f23ba8a7c9adcf652e8f34fdf247934ed1120 Mon Sep 17 00:00:00 2001 From: Aria Minaei Date: Tue, 13 Dec 2022 18:10:32 +0100 Subject: [PATCH] Remove unnecessary SSR warnings --- theatre/core/src/projects/Project.ts | 25 ++++++++++++++----------- theatre/studio/src/Studio.ts | 16 ++++++++++------ 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/theatre/core/src/projects/Project.ts b/theatre/core/src/projects/Project.ts index 551f946..910fb5b 100644 --- a/theatre/core/src/projects/Project.ts +++ b/theatre/core/src/projects/Project.ts @@ -113,15 +113,18 @@ export default class Project { } }, 0) } else { - setTimeout(() => { - if (!this._studio) { - if (typeof window === 'undefined') { - console.warn( - `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, ` + - `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 { + if (typeof window === 'undefined') { + if (process.env.NODE_ENV === 'production') { + console.error( + `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, ` + + `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,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`, ) } - } - }, 1000) + }, 1000) + } } } diff --git a/theatre/studio/src/Studio.ts b/theatre/studio/src/Studio.ts index ec3fa34..f183441 100644 --- a/theatre/studio/src/Studio.ts +++ b/theatre/studio/src/Studio.ts @@ -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,12 +107,15 @@ export class Studio { this._attachToIncomingProjects() this.paneManager = new PaneManager(this) - setTimeout(() => { - if (!this._initializeFnCalled) { - console.error(STUDIO_NOT_INITIALIZED_MESSAGE) - this._didWarnAboutNotInitializing = true - } - }, 100) + // 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) + this._didWarnAboutNotInitializing = true + } + }, 100) + } } async initialize(opts?: Parameters[0]) {