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

Can ModuleBlocks be stored in IndexedDB? #47

Open
surma opened this issue Mar 3, 2021 · 2 comments
Open

Can ModuleBlocks be stored in IndexedDB? #47

surma opened this issue Mar 3, 2021 · 2 comments
Labels
host environment Questions to be answered in each host environment

Comments

@surma
Copy link
Member

surma commented Mar 3, 2021

If they are strutured cloneable, they could technically also be stored in IndexedDB. Wondering if that’s useful and what the implications are.

Personally, I’m leaning towards not supporting that as I don’t have a clear use-case and I am worried about unexpected implications of allowing it.

@surma surma added the host environment Questions to be answered in each host environment label Mar 3, 2021
@Jack-Works
Copy link
Member

I support to not allow it being stored in the indexed db cause it seems like a security failure

@Jamesernator
Copy link

I can imagine one particularly nice use case and that would be the ability to associate deserialization steps with objects inside indexedDB. i.e. Libraries that wrap indexedDB could do something like:

import * as lib from "indexeddb-lib";

export default class MyCustomSerializableType {
    [lib.serialize]() {
        return {
            deserializerModule: module {
                import MyCustomSerializableType from "./MyCustomSerializableType.js";
                
                export function deserialize(serializedData) {
                    return new MyCustomSerializableType({
                        ...serializedData,
                    });
                } 
            },
            data: {
               // ...serialized data here
            },
    }
}
// Somewhere in the library code
const { deserializerModule, data } = await getEntryFromIndexedDBSomehow();
if (deserializerModule) {
    const { deserialize } = await import(deserializerModule);
    return deserialize(data);
} else {
    return data;
}

Although the implications for how this is stored would be weird, like what happens if the original module changes between page loads? Does a fresh copy get imported? Or do we cache the entire module graph for the module block and store this in the DB also and reevaluate that module graph too.

Either way around has weird implications, like if the module has changed but the module block hasn't the module block might no longer work. But if we cache the entire module graph then multiple versions of modules could be floating around.

I think at some point this might be worth supporting, but there is a large amount of discussion around how versioning would work to resolve the above concerns. For now I think the best action would just be throwing if attempting to serialize-for-storage would be best. If there's significant interest there could always be a follow up proposal with semantics around how these things get evaluated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
host environment Questions to be answered in each host environment
Projects
None yet
Development

No branches or pull requests

3 participants