Skip to content

fix(🌎): new __destroyWebGLContextAfterRender property to support more than 16 Skia canvases on Web#3349

Merged
wcandillon merged 6 commits intoShopify:mainfrom
wcandillon:web-contextes
Sep 5, 2025
Merged

fix(🌎): new __destroyWebGLContextAfterRender property to support more than 16 Skia canvases on Web#3349
wcandillon merged 6 commits intoShopify:mainfrom
wcandillon:web-contextes

Conversation

@wcandillon
Copy link
Copy Markdown
Contributor

@wcandillon wcandillon commented Sep 5, 2025

fixes #3331
fixes #3297
fixes #2343
fixes #956

Web browsers limit the number of WebGL contexts to 16 per webpage.
Usually developers will see this error when they exceed this limit:

WARNING: Too many active WebGL contexts. Oldest context will be lost.

If you canvas is static and doesn't contain animation values, you can use the __destroyWebGLContextAfterRender ={false} prop on your Canvas components to destroy the WebGL context after rendering.
This even works with animated canvases but it will come with a performance cost as the context will be recreated on each render.

import { View } from 'react-native';
import { Canvas, Fill } from "@shopify/react-native-skia";

export default function App() {
  return (
    <View style={{ flex: 1 }}>
      {
        // 20 Skia Canvases with __destroyWebGLContextAfterRender ={false}
        new Array(20).fill(0).map((_, i) => (
          <Canvas key={i} style={{ width: 100, height: 100 }} __destroyWebGLContextAfterRender={false}>
            <Fill color="lightblue" />
          </Canvas>
        ))
      }
    </View>
  );
}

@wcandillon wcandillon changed the title fix(🌎): add __webAnimation property to overcome 16 WebGL context limit on web fix(🌎): new __destroyWebGLContextAfterRender on to overcome WebGL context limit to 16 Sep 5, 2025
@wcandillon wcandillon changed the title fix(🌎): new __destroyWebGLContextAfterRender on to overcome WebGL context limit to 16 fix(🌎): new __destroyWebGLContextAfterRender property to support more than 16 Skia canvases on Web Sep 5, 2025
@wcandillon wcandillon merged commit 7a059e3 into Shopify:main Sep 5, 2025
11 checks passed
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Sep 5, 2025

🎉 This PR is included in version 2.2.10 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

1 participant