Pixi WeChat Black Screen
Use this skill when the game is already entering the WeChat mini-game runtime, but visibility is wrong or unstable. Focus on proving whether the failure is in entry execution, runtime preparation, canvas ownership, or actual rendering.
Workflow
Classify the failure before editing.
- If
game.jsorwechat-mainnever logs, treat it as an entry failure. - If
app-initorfirst-framelogs appear but the screen is black, treat it as a screen-canvas contract failure first, not a scene-content failure. - If the game renders on Web but not in WeChat, isolate all fixes to the generated entry,
platform/, and build layers.
- If
Enforce a single screen-canvas owner.
- Create exactly one screen canvas in generated
game.jsbefore loading the WeChat runtime bundle. - Bind that canvas to
globalThis.canvas,globalThis.screencanvas,GameGlobal.canvas, andGameGlobal.screencanvas. - Treat every later
wx.createCanvas()call as offscreen-only. - Do not let runtime code rediscover, rescore, or replace the screen canvas.
- Create exactly one screen canvas in generated
Keep runtime prep narrow.
prepareWeChatRuntime()must assert a prebound screen canvas exists.- Use runtime prep only for environment polyfills and DOM shims that Pixi actually needs.
- Do not scan
documentto choose a display canvas. - Do not create a fallback display canvas during runtime prep.
Keep the platform layer read-only with respect to canvas ownership.
WeChatPlatformshould only consume the prebound screen canvas.- Do not call
wx.createCanvas()in the platform layer. - Do not scan
document.querySelectorAll('canvas')in the platform layer.
Respect DevTools native DOM behavior.
- If a native
documentalready exists in DevTools, reuse it instead of replacing it. - Do not assign directly to a getter-only
window.document. - Do not assume
body.childrenis an array; native DOM may exposeHTMLCollection. - Maintain an internal child store for synthetic linkage instead of mutating native
children.
- If a native
Use temporary evidence, then remove it.
- In debug builds only, temporary probe graphics or pixel readback are acceptable to prove the screen canvas is visible.
- Once visibility is confirmed, remove the probes so they do not pollute normal debugging.
Validate both structure and outcome.
- Run the repo's typecheck, lint, tests, debug package build, and WeChat audit commands.
- Re-test in WeChat DevTools with the fresh debug package.
- If possible, verify on device after DevTools is green.
Guardrails
- Do not spread WeChat-specific canvas logic into shared scenes or gameplay systems.
- Do not keep multiple canvas-selection code paths alive at once.
- Do not trust
document.querySelector('canvas')as the source of truth in WeChat DevTools. - Do not mark the issue fixed until you have visual proof in DevTools or on device.
- Do not leave temporary probe overlays in release output.
Resource Map
references/workflow.md: step-by-step diagnosis and fix flowreferences/pitfalls.md: symptom-to-cause mapping and concrete failure patterns