Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix web compilation #88

Open
wants to merge 2 commits into
base: v3
Choose a base branch
from

Conversation

maxluchterhand1
Copy link

@maxluchterhand1 maxluchterhand1 commented Jun 18, 2024

Instead of storing the ids of the isar collections as integers, I moved the generation of those integers (which are just hashes of the name property) to runtime. this way, the dart code does not contain integers that cannot be represented in javascript.

@maxluchterhand1
Copy link
Author

I just realized that the hashing library (xxh3) itself also contains large integers that cannot be represented in javascript, fml.

../../.pub-cache/hosted/pub.dev/xxh3-1.0.1/lib/src/xxh3.dart:72:8: Error: The integer literal 0x9FB21C651E98DF25 can't be represented exactly in JavaScript.
Try changing the literal to something that can be represented in JavaScript. In JavaScript 0x9fb21c651e98e000 is the nearest value that can be represented exactly.
  h *= 0x9FB21C651E98DF25;
       ^^^^^^^^^^^^^^^^^^
../../.pub-cache/hosted/pub.dev/xxh3-1.0.1/lib/src/xxh3.dart:72:5: Error: A value of type 'num' can't be assigned to a variable of type 'int'.
  h *= 0x9FB21C651E98DF25;
    ^
../../.pub-cache/hosted/pub.dev/xxh3-1.0.1/lib/src/xxh3.dart:74:8: Error: The integer literal 0x9FB21C651E98DF25 can't be represented exactly in JavaScript.

However, I am pretty sure it is possible to implement the hashing algorithm in a JavaScript compatible way. I will continue working on this

still crashes when you attempt to call xxh3() in js runtime tho
@maxluchterhand1
Copy link
Author

maxluchterhand1 commented Jun 18, 2024

okay, I fixed the issue that I described in my previous comment in a very dirty way. basically, I just moved all of the code from https://pub.dev/packages/xxh3 into this package, and modified it in such a way that you can compile for javascript without getting the integer literal compile time error. however, the xxh3 algorithm still doesn't work in javascript, the exception is just moved to the runtime instead.

so basically, with my branch, you can import isar into your flutter project, use isar in all support platforms that are not web, and compile for web without errors. attempting to use isar on web will cause runtime errors.

why would this benefit anyone? we are using isar as part of a shared package that we use throughout many apps, including web apps. with the integer literal compilation error, we could no longer import that shared package in web apps and compile the app, even if we didn't use the isar part of the shared package in the web apps. and apparently, other people have similar issues. if you are one of those people/companies, you're welcome.

however, I find this solution pretty ugly. therefore, I am not sure whether this PR should really be merged. maybe you can use it as an inspiration to come up with a proper solution that actually WORKS on web, not just enables compilation. I, unfortunately, don't have time to continue down this rabbit hole

@maxluchterhand1 maxluchterhand1 changed the title fix web compatibility fix web compilation Jun 18, 2024
@vicenterusso
Copy link
Member

Have you tried this?

#82

@maxluchterhand1
Copy link
Author

Have you tried this?

#82

I tried that before I started working on this. I did not work. I can't remember what the exact problem was but I think the app wouldn't compile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants