TL;DR
- Pick the Web runtime by version and audio needs: for SVGA 2.0 animations without embedded audio, use actively maintained Web Lite (
svga2.1.1) (< 18 KBgzip with aWebWorkerparser). Use Web Classic (svgaplayerweb2.3.2) only when you need SVGA 1.x compatibility or embedded MP3 playback. - Silent Web audio comes down to four root causes: running
Web Lite(which skips audio), forgettinghowler.js(window.Howl), missing ID3v2 headers (SUQz), or browser autoplay locks. - Migrate Flutter apps from
svgaplayer_fluttertoflutter_svga: the archivedsvgaplayer_flutter(2.2.0) lags modern Dart 3 null safety. Adoptflutter_svgafrom pub.dev and disposevideoItemalongsideSVGAAnimationController. - Clean up Workers and textures on SPA unmount: in Vue 3, React 19, and Next.js, guard against SSR and call
player.stop(),player.clear(),player.destroy(), andparser.destroy().
Web player comparison: svgaplayerweb vs. Web Lite (svga)
| Dimension | svgaplayerweb (Web Classic 2.3.2) |
svga (Web Lite 2.1.1) |
|---|---|---|
| Upstream status (Dec 2026) | Repository archived read-only; package remains on npm | svga/SVGAPlayer-Web-Lite remains active |
| Bundle size | Larger runtime; requires external JSZip & howler for 1.x/audio |
Under 60 KB (< 18 KB gzip) |
| Format support | SVGA 2.0 and SVGA 1.x (with JSZip) |
SVGA 2.0 only |
| Threading & rendering | Main-thread parser + Canvas2D | WebWorker parser + OffscreenCanvas / ImageBitmap |
| Embedded MP3 audio | Supported (needs howler.js + ID3v2 header) |
Not supported |
| Dynamic slot APIs | player.setImage(url, key) / player.setText(opts, key) |
svga.replaceElements[key] = img / svga.dynamicElements[key] = canvas |
| Built-in cache | None out of the box | Built-in DB helper backed by IndexedDB |
Leak-free Vue 3 and React 19 / Next.js mounting patterns
Mounting SVGA animations inside modals or live rooms without tearing down Parser Workers leaks memory across route changes. Both snippets below guard SSR, pause on hidden tabs via visibilitychange, and handle rapid unmount cancellation:
React 19 / Next.js hook (SSR-safe)
'use client'
import { useEffect, useRef } from 'react'
import { Parser, Player } from 'svga'
export function SvgaLiteCanvas({ src }: { src: string }) {
const canvasRef = useRef<HTMLCanvasElement | null>(null)
useEffect(() => {
const canvas = canvasRef.current
if (typeof window === 'undefined' || !canvas) return
const parser = new Parser()
const player = new Player({
container: canvas,
loop: 0,
isCacheFrames: true,
isUseIntersectionObserver: true
})
let disposed = false
const handleVisibility = () => {
if (disposed) return
if (document.hidden) player.pause()
else player.start()
}
document.addEventListener('visibilitychange', handleVisibility)
parser
.load(src)
.then(async (videoItem) => {
if (disposed) return
await player.mount(videoItem)
if (!disposed) player.start()
})
.catch((err) => {
if (!disposed) console.error('SVGA load failed:', err)
})
return () => {
disposed = true
document.removeEventListener('visibilitychange', handleVisibility)
player.stop()
player.clear()
player.destroy()
parser.destroy()
}
}, [src])
return <canvas ref={canvasRef} width={360} height={360} />
}
Vue 3 <script setup> lifecycle
import { onBeforeUnmount, onMounted, ref } from 'vue'
import { Parser, Player } from 'svga'
const props = defineProps<{ src: string }>()
const canvasRef = ref<HTMLCanvasElement | null>(null)
let parser: Parser | null = null
let player: Player | null = null
let disposed = false
onMounted(async () => {
if (!canvasRef.value) return
parser = new Parser()
player = new Player({ container: canvasRef.value, loop: 0, isCacheFrames: true })
const videoItem = await parser.load(props.src)
if (disposed) return
await player.mount(videoItem)
player.start()
})
onBeforeUnmount(() => {
disposed = true
player?.stop()
player?.clear()
player?.destroy()
parser?.destroy()
})
Why Web audio plays silently (four root causes)
- Using
Web Lite(svga): Web Lite strips audio decoding to stay small. Switch tosvgaplayerweb@2.3.2or play audio separately via Web Audio if sound is mandatory. - Missing
window.Howl:svgaplayerwebchecks forwindow.Howl(howler.js) before decodingAudioEntitytracks; omittinghowler.min.jsresults in silent playback with no thrown exception. - Audio blob lacks an
ID3v2(SUQz) header: classicsvga.min.jsrequires embedded MP3 data to begin with an ID3v2 header (SUQzin Base64). Raw MPEG frames starting directly at0xFF 0xFBare ignored. Test your.svgatrack directly in the SVGA Online Player Audio tab to verify the payload. - Browser autoplay blocking: modern Chrome and Safari suspend unmuted audio started outside a user click/tap handler. Trigger playback inside an explicit gesture or expose a mute/unmute button.
Modern Flutter migration: svgaplayer_flutter → flutter_svga
Because svgaplayer_flutter (2.2.0) was archived at the end of 2022, current Flutter / Dart 3 projects should migrate to the maintained community package flutter_svga on pub.dev:
# pubspec.yaml (check pub.dev for the latest flutter_svga version)
dependencies:
flutter_svga: ^latest
import 'package:flutter/material.dart';
import 'package:flutter_svga/flutter_svga.dart';
class SvgaGiftWidget extends StatefulWidget {
final String url;
const SvgaGiftWidget({super.key, required this.url});
@override
State<SvgaGiftWidget> createState() => _SvgaGiftWidgetState();
}
class _SvgaGiftWidgetState extends State<SvgaGiftWidget>
with SingleTickerProviderStateMixin {
late final SVGAAnimationController _controller;
@override
void initState() {
super.initState();
_controller = SVGAAnimationController(vsync: this);
SVGAParser.shared.decodeFromURL(widget.url).then((videoItem) {
if (!mounted) {
videoItem.dispose();
return;
}
videoItem.dynamicItem.setImageWithUrl(
'https://example.com/avatar.png',
'avatar_slot',
);
_controller.videoItem = videoItem;
_controller.repeat();
});
}
@override
Widget build(BuildContext context) => SVGAImage(_controller);
@override
void dispose() {
_controller.stop();
_controller.videoItem?.dispose();
_controller.dispose();
super.dispose();
}
}
Key migration guidelines:
- Byte-level caching: cache downloaded
.svgabytes on disk withdioand calldecodeFromBuffer(bytes). Avoid mutatingdynamicItemon a single cachedMovieEntityinstance shared across concurrent widgets. - Flutter Web notes: serve
.svgafiles with CORS headers and cap bitmap dimensions to keep browser Canvas memory predictable. - HarmonyOS NEXT: target
@tb-open/svgavia OHPM as documented in the integration guide.
Ten production error fixes
| # | Symptom | Root cause | Fix & verification |
|---|---|---|---|
| 1 | Remote .svga fails to fetch on Web / mobile page |
Missing Access-Control-Allow-Origin header or mixed HTTP inside HTTPS |
Enable CORS on CDN and serve over HTTPS; verify URL reachability in Mobile Playback |
| 2 | Android release APK crashes or renders blank | ProGuard / R8 obfuscated Wire or SVGA Protobuf model fields | Add -keep class com.squareup.wire.** { *; } and -keep class com.opensource.svgaplayer.proto.** { *; } to proguard-rules.pro |
| 3 | matteKey masks disappear in recycled iOS cells |
Pre-2.5.7 VideoEntity reuse mask regression |
Upgrade to SVGAPlayer 2.5.7 (see Changelog) and call clearDynamicObjects() + clear() on cell reuse |
| 4 | Black or white halos around transparent glow edges | Premultiplied alpha artifacts or harsh PNG-8 quantization | Inspect over dark and light checkerboards in the SVGA Online Player |
| 5 | OOM crash when playing sequential gifts on low-RAM phones | Total ∑ w × h × 4 RGBA bytes too large or missing clear()/release() |
Trim oversized bitmaps and dedupe assets in the SVGA Online Compressor |
| 6 | Plays in viewer but fails in Web Lite or flutter_svga |
Input file is SVGA 1.x ZIP (50 4B 03 04 + movie.spec) |
Re-export or re-pack as SVGA 2.0 via the SVGA Format Converter Hub or Compressor |
| 7 | Android gift sound keeps playing after leaving screen | View detached without releasing SVGASoundManager |
Set clearsAfterDetached = true and call SVGASoundManager.release() |
| 8 | Next.js / Nuxt SSR throws window is not defined |
Instantiating Parser or Worker outside browser lifecycle hooks |
Move setup inside useEffect / onMounted with typeof window !== 'undefined' |
| 9 | Web setImage / replaceElements draws blank or taints canvas |
Cross-origin replacement image loaded without crossOrigin |
Set img.crossOrigin = 'anonymous' before setting img.src, then await img.decode() |
| 10 | Dynamic setImage / setText stops matching after export |
imageKey changed when designer renamed or flattened layers |
Inspect actual keys and copy matching 6-platform code from the SVGA Online Editor |
