Await font loading before first canvas render
The initial renderNow() fired before loadFonts() completed, causing text measurement to return null on slower connections (especially Safari). Layout computed without text dimensions got corrupted. Move loadFonts() into the async init() flow and only render after fonts are ready.
This commit is contained in:
parent
c52f88e34c
commit
29876f0c2b
|
|
@ -101,6 +101,8 @@ export function useCanvas(
|
|||
|
||||
await new Promise((r) => requestAnimationFrame(r))
|
||||
createSurface(canvas)
|
||||
await renderer?.loadFonts()
|
||||
if (!destroyed) renderNow()
|
||||
}
|
||||
|
||||
function sizeCanvas(canvas: HTMLCanvasElement) {
|
||||
|
|
@ -151,8 +153,6 @@ export function useCanvas(
|
|||
const glCtx = canvas.getContext('webgl2') ?? null
|
||||
renderer = new SkiaRenderer(ck, surface, glCtx)
|
||||
editor.setCanvasKit(ck, renderer)
|
||||
void renderer.loadFonts().then(() => renderNow())
|
||||
renderNow()
|
||||
canvas.dataset.ready = '1'
|
||||
options?.onReady?.()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue