Coder Social home page Coder Social logo

Comments (7)

simolus3 avatar simolus3 commented on June 11, 2024

Thanks for the report, I'll try to reproduce this with an example from this repository.

However, storage doesn't function as anticipated.

Is it just completely broken without giving any error message or is there more that might be relevant?

In private mode, additional missing features are noted:

Does it also pick sharedIndexedDb there?

from drift.

Dall127 avatar Dall127 commented on June 11, 2024

it does pick sharedIndexedDb

I believe that it successfully creates the Database (i.e. in my debug panel I can see the expected db got created)

though afterwards, nothing is getting stored. Normally I'd get a dropdown showing at least a little of what got stored,
(as shown on pre-migration)
Screenshot 2023-12-29 at 4 17 28 PM

After migration
Screenshot 2023-12-29 at 4 19 17 PM

So I'm making the assumption that nothing is getting stored. My initial (blindly attempting) pull request's goal was to see if perhaps there was an issue with utf-8, as for why we discussed I don't think that's the case.

output from private mode: Using WasmStorageImplementation.sharedIndexedDb due to missing browser features: {MissingBrowserFeature.dedicatedWorkersInSharedWorkers, MissingBrowserFeature.fileSystemAccess, MissingBrowserFeature.sharedArrayBuffers}

Alls to say, my bet would be that there's something fishy with the fileSystemAccess on Safari if the lack thereof makes the implementation work

from drift.

Dall127 avatar Dall127 commented on June 11, 2024

Update: I think the initial trail might have been a little misleading; there's two new things that might give you clue to what's up.
I've found potential solution for the Safari normal mode issue. This might have been a migration-to-wasm issue, though I was sure to rename the db after migrating. Not completely sure.

However, there's a new twist in Safari's private mode: storage works correctly on the first load, but fails on subsequent reloads. This is a different layer to the problem, suggesting an issue with Safari's handling of data storage and retrieval across different browsing sessions. It doesn't occur on private mode in other browsers.

@simolus3 , If you have a discord, I can PM you a link to the site with the issue. It'll be a black box, but at least you'll be able see what states get you into what

from drift.

simolus3 avatar simolus3 commented on June 11, 2024

Sure, my Discord username is simonbinder

from drift.

SleepySquash avatar SleepySquash commented on June 11, 2024

I might add some strange things discovered in Safari 17.4.1. It seems like deploying web application with Cross-Origin-Embedder-Policy header set to require-corp breaks the WasmDatabase entirely (Safari only, other browsers have no issues). The application initializes and works perfectly fine with the first run, however on each following page refresh the drift throws the error in the console, unable to initialize:

Screenshot 2024-05-21 at 11 10 52

Note: I'm building the examples/app application (cd examples/app && dart run build_runner build && flutter build web) and then deploying it with the following command:

dhttpd '--headers=Cross-Origin-Embedder-Policy=require-corp;Cross-Origin-Opener-Policy=same-origin' --path build/web/

The drift picks IndexedDB for storage:

Using WasmStorageImplementation.sharedIndexedDb due to unsupported browser features: {MissingBrowserFeature.dedicatedWorkersInSharedWorkers}

And the culprit seems to be the IndexedDB's database not being populated, as like WasmDatabase doesn't have the write access (it should contain blocks, etc):

Screenshot 2024-05-21 at 11 21 10

What's even more strange is the fact that deploying application without the COEP/COOP headers works fine and even deploying the COEP with credentialless works fine! However, when COEP is set to credentialless, the drift seems to consider SharedArrayBuffers as being unavailable:

Using WasmStorageImplementation.sharedIndexedDb due to unsupported browser features: {MissingBrowserFeature.dedicatedWorkersInSharedWorkers, MissingBrowserFeature.sharedArrayBuffers}

Yet I can confirm the headers are set:

Screenshot 2024-05-21 at 11 11 54

Perhaps Safari with COEP set to require-corp needs some additional deployment configuration? I'll try to investigate this a bit and leave a comment, if something is up.

UPD. The bug mentioned at https://drift.simonbinder.eu/web/#additional-headers might be related, however I'm not sure: https://bugs.webkit.org/show_bug.cgi?id=254065. Also it seems to have RESOLVED FIXED status.

from drift.

simolus3 avatar simolus3 commented on June 11, 2024

Thanks for the report! Did you already have a database from a previous run in the first screenshot? Drift should pick opfsLocks here, unless it detects that the IndexedDB database already exists (so that no data is lost).

However, when COEP is set to credentialless, the drift seems to consider SharedArrayBuffers as being unavailable:

When I tried that, crossOriginIsolated also reported false in the console - so shared buffers really are unavailable.

The problem, I think, comes from here:

/// Returns whether an drift-wasm database with the given [databaseName] exists.
Future<bool> checkIndexedDbExists(String databaseName) async {
bool? indexedDbExists;
try {
final idb = globalContext['indexedDB'] as IDBFactory;
final openRequest = idb.open(databaseName, 1);
openRequest.onupgradeneeded = (IDBVersionChangeEvent event) {
// If there's an upgrade, we're going from 0 to 1 - the database doesn't
// exist! Abort the transaction so that we don't create it here.
openRequest.transaction!.abort();
indexedDbExists = false;
}.toJS;
final database = await openRequest.complete<IDBDatabase>();
indexedDbExists ??= true;
database.close();
} catch (_) {
// May throw due to us aborting in the upgrade callback.
}
return indexedDbExists ?? false;
}

We're checking whether an IndexedDB database exists because, if it does, we don't want to use OPFS even it is available. The problem is that (despite aborting the transaction) we seem to create the database inadvertently with that check. That's a big problem, because it now means that as soon as we reach a state where OPFS doesn't exist/is unavailable, we'll try to use that broken database.

Most browsers support indexedDb.databases though, I'll migrate the check to that if it's supported to avoid creating the database here.

from drift.

simolus3 avatar simolus3 commented on June 11, 2024

So I've fixed that in 996176d, but that only prevents new versions from accidentally creating a bogus database. Depending on how widespread this problem is we may have to bump the schema version for IndexedDB and create the stores if they don't exist.

from drift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.