PixiJS 7: Automatic Renderer Resizing Removed – What’s the Plan for Legacy Apps?
26.5K reputation · 02 Dec 2024, 11:00 UTC
Background
PixiJS 7 dropped the automatic canvas size adjustment that matched the browser viewport. Applications that previously relied on the renderer resizing themselves must now set width/height or handle window events manually.
Current Constraints
Legacy code written for PixiJS 6 will break if the canvas is not explicitly resized. There is no built‑in flag to restore the old behaviour, and the renderer API no longer accepts a “resizeTo” option.
Unresolved Decision
The PixiJS core team has not announced whether an automatic resizing shim will be re‑introduced or if a dedicated compatibility layer will be provided for projects that cannot immediately refactor their resize logic.
Questions
1. Will the PixiJS 7 release include a configurable option to re‑enable automatic renderer resizing for backward compatibility?
2. If not, what is the recommended strategy for preserving the old auto‑resize behaviour in large codebases?
3. Are there any planned deprecation timelines for projects that rely on the previous resizing feature?
1 answer
1 question comment
Use comments to ask for clarification. Post a solution as an answer.
1,660 reputation · 02 Dec 2024, 19:09 UTC
While implementing a global resize listener solves the internal buffer issue, it is important to clarify the interaction between the renderer and CSS. In PixiJS 7, if your canvas is styled with width: 100% or height: 100% in CSS, the browser will scale the canvas element visually, but the internal drawing buffer remains at the size set during the last renderer.resize() call.
To avoid the blurriness mentioned in previous responses, ensure your resize logic accounts for the actual layout size of the canvas element rather than just the window dimensions, especially when the canvas is nested within a flexible container:
window.addEventListener('resize', () => {
const canvas = app.renderer.view;
// Use clientWidth/Height to match the actual CSS-rendered size
app.renderer.resize(canvas.clientWidth, canvas.clientHeight);
});
For projects using autoDensity: true, remember that this scales the resolution based on window.devicePixelRatio, but it does not automate the dimension updates. Manual verification of the canvas.width and canvas.height attributes is recommended to ensure they match the intended CSS layout.