Skip to content

Offline modus or pending connect #156

Open
@SebastianStehle

Description

@SebastianStehle

Checklist

[x] Are you reporting a bug? Use github issues for bug reports and feature requests. For general questions, please use https://discuss.yjs.dev/
[x] Try to report your issue in the correct repository. Yjs consists of many modules. When in doubt, report it to https://github.com/yjs/yjs/issues/

Is your feature request related to a problem? Please describe.

When a change happens and the provider is not connected yet and or currently offline, the change is lost.

Describe the solution you'd like

At the moment messages are only sent, when the websocket is available. Otherwise the update is just lost. The API also does not provide any methods to deal with initial connect in a nice way.

I have a react effect that connects to a y-sweet server whenever a ID changes. So it works like this:

React.useEffect(() => {
    const doc = new Y.Doc();
    const provider = createYjsProvider(...);
    init(doc, id);
}, [id]);

But when init is called, the doc is provider is not available yet. Therefore I had to wait for the connection to be established

React.useEffect(() => {
    const doc = new Y.Doc();
    const provider = createYjsProvider(...);
    await new Promise(resolve => {
            const handler = () => {
                if (provider.wsconnected) {
                    resolve(true);
                }
            };

            provider.on('status', handler);
        });
    init(doc, id);
}, [id]);

I think there should be a limited queue to handle this problem or network hiccups.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions