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,15 +115,22 @@ export default class Project {
} else { } else {
setTimeout(() => { setTimeout(() => {
if (!this._studio) { 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 {
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 ` +
`is not loaded, the state of project "${id}" will be empty.\n\n` + `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 ` + `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://docs.theatrejs.com/in-depth/#exporting\n` + `the project's state. Learn how to do that at https://www.theatrejs.com/docs/latest/manual/projects#state\n`,
`If you are using a framework like Next.js, this error may be caused by running Theatre on the server side.`,
) )
} }
}
}, 1000) }, 1000)
} }
} }