Shopify / Shopify/react-native-skia

First frame renders transparent canvas

Open
#2,968 10 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug released released on @next
Dominant language
TypeScript
Stars
8.6k
Forks
647
Avg merge
1d 17h
Merged PRs (30d)
35

Description

Description

Our app uses a Skia's canvas as a background for the home screen, and the first render always comes through transparent, although there are elements to be rendered.

We have debugged the issue and believe there are 2 places that cause this behaviour: Canvas component supplying children collection in useEffect and missing waitUntilCompleted call to commandBuffer in MetalWindowContext class.

We have attempted to fix it on our end by adding root.render(children) to the memoized creation of SkiaSGRoot inside Canvas component and added a bool flag to present() method to enforce command buffer completion when immediate draw is requested (e.g. from drawRect of the view).

We are happy to open a PR with these fixes, but figured it's a good idea to create a bug first and get a confirmation that it is a real issue and our solution is worth submitting.

React Native Skia Version

1.11.1

React Native Version

0.76.6

Using New Architecture
  • Enabled
Steps to Reproduce
  1. Add a canvas with some background color to the view
  2. Add an element (e.g. a circle) to the canvas
  3. Put the canvas onto any screen of the app
  4. Navigate to the screen and observe a flash
Snack, Code Example, Screenshot, or Link to Repository

Please have a look at two recordings from iOS Simulator (iPhone 16 Pro, iOS 18.1) where a screen with Canvas as a background opens (following a white flash). In both cases, the Canvas's style set to [StyleSheet.absoluteFill, {backgroundColor: "lime"}] and the first video shows a green flash, which is not present in the second video.

before fix after fix

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the first-render flash using the Canvas component on the listed React Native and iOS versions, then inspect its useEffect handling of children and the commandBuffer flow in MetalWindowContext. Compare behavior with the two proposed changes; done means the first canvas render displays its elements without a transparent or background-color flash.

Written by the indexing model from the issue text.

Assessment

Tech stack
react-native, typescript
Domain
mobile-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.