Comments (7)
Ah, I should have explained!
We've implemented a schema versioning system. Anytime new node types are added or existing ones modified, we bump a schema version in the code. Any client that connects to Hocuspocus passes its schema version via a query param.
If a user on schema version 1 is connected and editing the doc, then a user with schema version 2 connects, the user on schema version 1 must be put in read only mode and asked to reload, as their client may not be able to understand the content of the newer schema.
Another simpler use case is that a client's access level changes. If the user keeps a long lived connection to a document, their permissions could change and either require that their connection is set to read only or closed.
from hocuspocus.
What if you’d have access to other connections in the onConnect
hook? So you could write something like that:
async onConnect({ requestParameters, connection }) {
// All connections to this document …
connections
// … with an older version …
.filter(connection => requestParameters.version > connection.requestParameters.version)
// … should be closed …
.forEach(connection => {
// … with a proper code and message.
connection.close(Outdated.code, Outdated.reason)
})
}
from hocuspocus.
@jamesopti What do you think? Would that help? 🙃
from hocuspocus.
Out of interest: How does the client get notified that the schema is outdated? The schema version is stored in the Y.js document?
Yup, exactly. We set a property on the doc like this:
async onCreateDocument({ document, documentName }) {
document.getMap(this.configuration.metaDataKey).set('READY', false)
await this.load(documentName)
// Apply updates
...
document.getMap(this.configuration.metaDataKey).set('READY', true)
}
@jamesopti What do you think? Would that help? 🙃
So this would partially solve our problem (the piece where the document is already loaded into memory).
But we also need to handle the case where the document has not been loaded, for example:
- Document in cold storage (postgres) is at version 4
- New client connects with version 3
- Document is fetched from cold storage
- Document version 4 is newer than connecting client (version 3)
- Connecting client must now be put in readonly mode
Perhaps onCreateDocument
also needs to know the connection
which triggered it to fire?
from hocuspocus.
I think it's worth considering how this versioning usecase could be a first class citizen of Hocuspocus. The other implementation of yjs
that I've taken to production had to have exactly the same considerations, because the way that y-prosemirror
is written if a node isn't understood it's just filtered out (deleted).
https://github.com/yjs/y-prosemirror/blob/master/src/plugins/sync-plugin.js#L448-L455
This means you absolutely cannot have old client versions connected or you'll lose content from newer clients as soon as they load it 🙈
from hocuspocus.
In which hook you'd like to set the connection to readOnly? I’d assume in the onChange
hook?
Would you mind to elaborate on the use case? I think once someone is able to write to the document, it seems frustrating to ignore changes later (after the users was idle or something).
And would you make it writeable again at some point? That would mean we’d need to trigger another hook for blocked changes.
from hocuspocus.
Ah, got it! That’s a great use case.
Out of interest: How does the client get notified that the schema is outdated? The schema version is stored in the Y.js document?
from hocuspocus.
Related Issues (20)
- 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
- Connections to doc are possible while `onLoadDocument` is still in progress
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.