realm-dart icon indicating copy to clipboard operation
realm-dart copied to clipboard

Web support

Open maxkrieger opened this issue 3 years ago • 27 comments

Since Realm already has a JS client, would it be easy enough to add a web compatible variant to this package?

maxkrieger avatar Apr 09 '21 19:04 maxkrieger

This would be awesome

richard457 avatar May 14 '21 05:05 richard457

We are certainly interested in supporting Flutter Web as a platform but it will require web assembly support and our Core team is exploring the various options we have. This is still at very early stages of research so we can't do any commitments currently

blagoev avatar May 14 '21 10:05 blagoev

wouldn't js with indexedDB be enough ? Last I checked the js client was just allowing graphql queries

cedvdb avatar May 22 '21 07:05 cedvdb

wouldn't js with indexedDB be enough ?

I think the point is to have a cross-platform database on Flutter (android, ios, web and other supported platforms).

calvintam236 avatar May 27 '21 23:05 calvintam236

Would love to see web support as well!

markbreuss avatar Apr 12 '22 17:04 markbreuss

Hi, any updates on this one?

hmbenhaim avatar Oct 23 '22 00:10 hmbenhaim

From a local persistent DB perspective; not sure how beneficial this is for Flutter Web as persistent local databases in web browsers are usually not a great approach from a data security perspective...

dotjon0 avatar Oct 23 '22 02:10 dotjon0

From a local persistent DB perspective; not sure how beneficial this is for Flutter Web as persistent local databases in web browsers are usually not a great approach from a data security perspective...

From what I understand the web support in general of realm is not local db just a sync from the cloud and it's available for js just ask to add it to flutter web

https://www.mongodb.com/docs/realm/web/

hmbenhaim avatar Oct 23 '22 09:10 hmbenhaim

they should add support for GraphQL subscriptions

ajonno avatar Jan 31 '23 22:01 ajonno

Any updates? web assembly is now in a further stage with flutter web since the last keynote a couple weeks ago.

JakobStadlhuber avatar Feb 12 '23 01:02 JakobStadlhuber

Support for web assembly is not on our short-term roadmap. As @blagoev said, we are interested in eventually supporting it as a platform and are doing some preliminary work there, but we don't currently expect this to materialize in something user-facing before the end of 2023.

If you would like to use App Services in a web assembly project, the recommendation is to use GraphQL or the Data API which are both accessible using a simple http client or via a 3rd party package, such as graphql_flutter.

nirinchev avatar Feb 13 '23 12:02 nirinchev

I understand. I just wanted to make it clear that there is a big opportunity in the growing flutter community for you. Developing once for Web, App, and the Desktop Client with realm/app service as a backend/data solution sounds amazing. We will probably use it anyway but we have to write a separated codebase just for the web, because there is no web support with flutter realm. I hope you see the big potential with really just one codebase for companies/startups....

JakobStadlhuber avatar Feb 13 '23 13:02 JakobStadlhuber

We are aware of it and are definitely interested in catering to the needs of businesses that would like to share a codebase between their native and web apps. The main blocker here is that the database as well as the sync layer is written in C++ (in order for us to share it across all supported platforms). Web Assembly imposes certain restrictions/has some peculiarities when it comes to IO and multithreading that require significant work to support. We're working on it and making some progress there, but I wanted to be upfront about the timelines so that you folks can make the best design choices for the architecture of your project. If you're looking to ship something in the next 3-6 months, it would be a mistake to wait for WebAssembly support in the Flutter SDK. If you're working on a huge project that will ship in 2024 or later, then definitely reach out to your account executive (if using any of our paid services) and they should be able to work with you and share more precise timelines as well as relay your requirements to the engineering team.

nirinchev avatar Feb 13 '23 13:02 nirinchev

Now that Flutter 3.10 is released and supports WASM, would it be possible to use Realm on web?

realrk95 avatar May 17 '23 10:05 realrk95

@realrk95 It has limited support. I believe adding support for the web is still a challenging task.

minikin avatar May 17 '23 10:05 minikin

For the interested (in case you missed it) there is a preview in the realm-js SDK for for proper Realm support including full Atlas Device Sync. This is based on compiling realm-core to wasm with emscripten. Take note that it has significant limitations.

NOTE: It is only for javascript, not Dart.

nielsenko avatar Aug 28 '23 11:08 nielsenko

@nielsenko not sure where's best to give this feedback, but the next absolute game changer would be to figure out how to connect other wasm efforts such as SwiftWASM into this new realm-js work such that Swift code (or other langs which Realm supports) can be used for both mobile and web including the Realm usage. JS is great for cross-platform, but there are many Swift / native app developers who are looking for cross-plat solutions too and this brings us closer to that. Thanks

aehlke avatar Aug 29 '23 16:08 aehlke

@aehlke I'm not familiar with SwiftWASM, but feel free to open a feature request in https://github.com/realm/realm-swift

nielsenko avatar Aug 29 '23 19:08 nielsenko

@nirinchev @blagoev You can see nice solution that uses Wasm SQLite or IndexedDB depends on web browser: Drift library: https://drift.simonbinder.eu/web/#storages

zs-dima avatar Aug 31 '23 13:08 zs-dima

@zs-dima I'm well aware of the work of Simon Binder (@simolus3). I used to use Drift (or moor as it was called back then) a lot. Another database that support web is isar by Simon Choi (@simc). I can highly recommend both, if synchronisation is not important to you, and you need web support now.

nielsenko avatar Aug 31 '23 13:08 nielsenko

@nielsenko thanks a lot for the answer, I cannot reccommend ISAR alghthough. It has critical issues with isolates for example. https://github.com/isar/isar/issues/1112 https://github.com/isar/isar/issues/1199 . . . In the same time community and all my projects are happy with Drift. Sorry for the offtopic.

zs-dima avatar Aug 31 '23 14:08 zs-dima

@zs-dima Please observe https://www.mongodb.com/community-code-of-conduct. I can't speak for @nirinchev, but I stand by my word.

nielsenko avatar Aug 31 '23 16:08 nielsenko

Any update on this?

rodrigoreal avatar Feb 06 '24 23:02 rodrigoreal

When we have an update, we will be sure to post it in the issue.

nirinchev avatar Feb 06 '24 23:02 nirinchev

Sorry for my ignorance, but why doesn't it work on web apps?

juppdes avatar Mar 13 '24 18:03 juppdes

The Realm database is built in C++ and the features it uses - particularly around filesystem access - are not available in the web. The Realm Flutter SDK is wrapping the C++ database to expose ergonomic API to read/write data from dart/flutter apps, but the platforms we support are limited by the platforms the native database supports.

nirinchev avatar Mar 13 '24 20:03 nirinchev

To elaborate on @nirinchev's answer.

We would need to compile realm-core (or actually librealm_dart.so which includes the former) to WASM. Some ground work has been done to this end, but we are not done.

One complication is that realm uses mmap'ed IO, which is not supported by the WASM runtimes of the browsers. We either need to

  • wait for the WASM memory-control proposal to be ratified and implemented in a majority of runtimes,

  • rewrite significant parts of realm-core to avoid the strict dependency on mmap, or

  • forego persistence (as we do in the JS web sync preview)

Also, we are using dart:ffi to call into native code. Dart FFI is not supported with Flutter Web (yet). This means we will have to manually create a JS interop based binding instead.

Add on top of this that some browsers still don't even support WasmGC - which is pre-requisite for compiling flutter code to WASM. This means we would have to support compiling to javascript, just to run in Safari. Or any browser on iOS, as they all forced to use WebKit (except in the EU as of iOS 17.4). Which again will require some work-around regarding the dreaded 53 bit integers.

This is just a lot of risky external dependencies, and/or a ton of work that has to be prioritized among other stuff. That said, we are well aware that this is the most upvoted feature in the repo. So stay tuned, but be very patient 🙏 ..

nielsenko avatar Mar 13 '24 21:03 nielsenko