Comments (5)
@hanspagel just tested this and works well 😀 . I had a suspicion something wasn't working quite right I thought you made synced
separate to onCreateDocument
incase it was slow to create, didn't realise that was the bug!
from hocuspocus.
Oh, this appears to happen when the onCreateDocument takes "longer". I refactored the server to wait for all onCreateDocument hooks before sending the first sync step.
synced
should now work for your use with the new version. Would you mind to try again? I’m doing a release now.
EDIT: Published new versions.
from hocuspocus.
Oh, good catch!
from hocuspocus.
The connect
event is emitted, when the first message is received (and before it is applied). I think that’s what I’d expect.
hocuspocus/packages/provider/src/HocuspocusProvider.ts
Lines 324 to 328 in 5c5f484
And the synced
event seems to be emitted when the update is applied already.
hocuspocus/packages/provider/src/MessageReceiver.ts
Lines 46 to 55 in 5c5f484
Tested in:
https://github.com/ueberdosis/hocuspocus/blob/main/tests/provider/onSynced.js#L75-L101
Or do I miss something?
from hocuspocus.
@hanspagel I didn't actually check the synced
event as the document is not ready when synced
is called if onCreateDocument
needs to be called so can ignore that.
The issue I'm seeing is that the message
event which carries my initial document (as returned from onCreateDocument
in @hocuspocus/server
) is fired before that update is actually applied to the document because of:
hocuspocus/packages/provider/src/MessageReceiver.ts
Lines 46 to 55 in 5c5f484
To show a loading state and remove it when the document is definitely received from the server I currently have to do the following:
const document = new Y.Doc();
const provider = new HocusPocus({ document, ... });
let timeout: number;
function checkIfLoaded() {
// have to wrap this in setTimeout because the message event is fired before the update is applied to the document
clearTimeout(timeout);
timeout = setTimeout(() => {
// checks if data actually exists in the document
if (isLoaded(document)) {
provider.off('synced', checkIfLoaded);
provider.off('message', checkIfLoaded);
onLoad();
}
}, 0);
}
// document may be empty after synced if it hits onCreateDocument in @hocuspocus/server
provider.on('synced', checkIfLoaded);
provider.on('message', checkIfLoaded);
from hocuspocus.
Related Issues (20)
- Hocuspocus >=2.7.0 does not work with React in strict mode / Lexical HOT 5
- Support logging request/socket information in custom Logger.log function HOT 1
- Unsure how to fallback gracefully from initial provider connection issues HOT 2
- Migrate from slate js to prosemirror HOT 1
- Unnecessary onStoreDocumentHooks call on last connection close (potential data loss) HOT 1
- Provider downloads document content twice when syncing initially HOT 1
- Hang caused by not cleaning up Awareness in provider HOT 1
- Do collaboration history and auto-versioning work? HOT 1
- Add custome field to the Webhook
- Provider.disconnect prevents subsequent provider.connect from working HOT 1
- 2.10.0 breaks provider in nodejs HOT 7
- The server document judgment is always empty, resulting in duplicate data. HOT 2
- backend onChange undefined HOT 2
- Server crashed when webhook receives 400 status code response HOT 3
- Inaccurate document type check in onLoadDocument
- use lexical TypeError: The encoded data was not valid for encoding utf-8 HOT 1
- Updates made using openDirectConnection are not synchronizing changes across different Redis instances. HOT 9
- provider.destroy will reopen connection HOT 2
- About the actual storage size of documents during collaborative editing HOT 8
- An authentication token is required, but you didn’t send one - but token was actually included HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hocuspocus.