excaliburjs / Excalibur

🎮 Your friendly TypeScript 2D game engine for the web 🗡️
https://excaliburjs.com
BSD 2-Clause "Simplified" License
1.83k stars 192 forks source link

Create Next.js template or example #2016

Open kamranayub opened 3 years ago

kamranayub commented 3 years ago

Here's an example of using Excalibur with Next. Since Excalibur can only execute on the client, it needs to be loaded via useEffect and a dynamic import otherwise Next will attempt to run the module in SSR. Unfortunately, right now we don't check for window existence so it bombs in SSR.

https://codesandbox.io/s/next-excalibur-5b18x?file=/game/game.js

FYI, this is still an issue in 0.24.5 which is exacerbated by HMR: https://github.com/excaliburjs/Excalibur/issues/1431

Working around by clearing the element by tag name/query selector when effect runs.

Originally posted by @kamranayub in https://github.com/excaliburjs/Excalibur/discussions/1886#discussioncomment-1309321

eonarheim commented 3 years ago

Should this issue be restructured to gracefully fail if no window is present?

kamranayub commented 3 years ago

Well I think we'd still like a template or example, and then the other issue is failing gracefully with no window

github-actions[bot] commented 2 years ago

This issue hasn't had any recent activity lately and is being marked as stale automatically.

github-actions[bot] commented 1 year ago

This issue hasn't had any recent activity lately and is being marked as stale automatically.