[Cocos Creator 3.8.8] Correct way to destroy/cleanup an embedded game in an SPA to avoid getGFXTexture errors

I’m running into a tricky issue with Cocos Creator 3.8.8 and could use some advice from anyone who’s done something similar.

I have a game built with Cocos Creator, and it’s embedded as just one part of a larger Single Page Application (SPA). Think of it like a game widget on a specific page. When a user navigates away from that page, I need to completely tear down the Cocos instance to free up memory—no leaks, no leftover resources.

I’ve built a cleanup method that does what seems logical: pausing the game and director, stopping sounds, destroying the scene, clearing caches, releasing the WebGL context, etc. The game does stop.

But here’s the problem: right after calling my destroy() method, the browser console gets spammed with this error:

cc.js:1 Uncaught TypeError: Cannot read properties of null (reading 'getGFXTexture')

It looks like the engine’s internal loop is still trying to run and render after I’ve already cleaned up the textures and resources.

My core question is: In Cocos Creator 3.8.x, what is the correct order or API calls to fully shut down the engine on the web? How do I ensure the internal render/update loops are completely halted before I start destroying graphics resources?

Has anyone successfully embedded and then cleanly destroyed a Cocos game within an SPA? Any pointers on what I might be missing in the teardown sequence would be a lifesaver.

Thanks in advance!