Describe the bug
This took me a while to figure out this morning (LLMs also have no idea)
When passing Svelte 5 $state variables to native bridged code (via Capacitor in this instance) you can get a "DataCloneError: The object can not be cloned." error on iOS
Reproduction
import { AdMob, BannerAdSize } from '@capacitor-community/admob';
bannerOptions = $state({
adId: unitId,
adSize: BannerAdSize.ADAPTIVE_BANNER,
position: BannerAdPosition.BOTTOM_CENTER
});
await AdMob.showBanner(bannerOptions);
// Work around, use spread operator (or $state.snapshot):
await AdMob.showBanner({ ...bannerOptions });
Logs
[Error] Unhandled Promise Rejection: DataCloneError: The object can not be cloned.
postMessage
postToNative (user-script:2:847)
(anonymous function) (user-script:2:904)
(anonymous function) (user-script:2:993)
Promise
(anonymous function) (user-script:2:992)
(anonymous function)
System Info
System:
OS: macOS 15.7.1
CPU: (14) arm64 Apple M3 Max
Memory: 602.67 MB / 36.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.19.0
Yarn: 1.22.22
npm: 11.6.1
Browsers:
Chrome: 142.0.7444.162
Firefox: 143.0.1
Safari: 26.0.1
npmPackages:
svelte: ^5.0.0-next.1 => 5.16.2
Severity
annoyance