Show more helpful warnings in SSR mode

This commit is contained in:
Aria Minaei 2022-09-17 19:14:07 +02:00 committed by Aria
parent 3c9481f1b7
commit 5bb4fc9340

View file

@ -115,14 +115,21 @@ export default class Project {
} else { } else {
setTimeout(() => { setTimeout(() => {
if (!this._studio) { if (!this._studio) {
throw new Error( if (typeof window === 'undefined') {
`Argument config.state in Theatre.getProject("${id}", config) is empty. This is fine ` + console.warn(
`while you are using @theatre/core along with @theatre/studio. But since @theatre/studio ` + `Argument config.state in Theatre.getProject("${id}", config) is empty. ` +
`is not loaded, the state of project "${id}" will be empty.\n\n` + `This is fine on SSR mode in development, but if you're creating a production bundle, make sure to set config.state, ` +
`To fix this, you need to add @theatre/studio into the bundle and export ` + `otherwise your project's state will be empty and nothing will animate. Learn more at https://www.theatrejs.com/docs/latest/manual/projects#state`,
`the project's state. Learn how to do that at https://docs.theatrejs.com/in-depth/#exporting\n` + )
`If you are using a framework like Next.js, this error may be caused by running Theatre on the server side.`, } else {
) 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 ` +
`is not loaded, the state of project "${id}" will be empty.\n\n` +
`To fix this, you need to add @theatre/studio into the bundle and export ` +
`the project's state. Learn how to do that at https://www.theatrejs.com/docs/latest/manual/projects#state\n`,
)
}
} }
}, 1000) }, 1000)
} }