Comments (12)
Thanks for the report! I'm not sure I fully understand the issue (I've not used the ot-tree
type personally). Could you please provide a minimally-working reproduction, ideally with a failing test case.
from sharedb.
OK,I will provide more details tomorrow
from sharedb.
I posted a minimally-working project in https://github.com/TianBM/mini-ot
from sharedb.
Hi thanks for this. I see you've included a hand-rolled OT type in here. Is this your own type? Is the bug with the type or with ShareDB?
Also I don't fully understand this type. Could you please write a failing test case, with some assertion on the expected final state.
from sharedb.
I found it on GitHub and noticed that json1 has the same issue. I’m writing a unit test for ShareDB to help identify and fix the problem. I believe that ShareDB should ensure the operation (op) isn't modified, even if some OT types may change the op object.
from sharedb.
There are some json1
tests here already. Probably a good place to chuck a new test, and should hopefully give you a good starting point for a new test.
from sharedb.
yeah, I noticed that json0 has the clone op operation, which avoids using the same object for the push method and the apply method, so I would suggest that clone could be added before the sharedb's ottype.apply call to ensure that they don't affect each other
from sharedb.
I think this is a bug in ot-tree, but I also hope sharedb will consider my proposal to add the clone method before the ottype.apply call, to avoid the push method and the apply method affecting each other
from sharedb.
I agree cloning would be safest, but it does come with performance and maintenance penalties.
According to the docs:
apply(snapshot, op) -> snapshot': Apply an operation to a document snapshot. Returns the changed snapshot. For performance, old document must not be used after this function call, so apply may reuse and return the current snapshot object.
...the snapshot
actively isn't guaranteed immutable, but no mention is made of the op, which I personally would read as: the type should not mutate the op, and it's a concern of the type to clone the op if it needs to mutate it for internal work.
Further, I think if the type mutates the op, I'm pretty sure it breaks this property of transform
:
Transform must conform to Transform Property 1. That is, apply(apply(snapshot, op1), transform(op2, op1, 'left')) == apply(apply(snapshot, op2), transform(op1, op2, 'right'))
If apply()
mutates the ops, I'm pretty sure you can't guarantee Transform Property 1, so the type is broken.
Also, there's points in ShareDB where we directly call type.apply()
, and I don't think it should be a concern of ShareDB to have to clone before every call to this.
from sharedb.
I agree that ops shouldn't be mutable, but there are certain cases where, for example, the op object is added directly to the snapshot, in which case the ot-type may have all the behaviors met, but is affected by the subsequent apply method because it's not cloned
from sharedb.
That's true, but I'd still say that would probably fail Transform Property 1 I suspect. If a type is well-behaved, and knows that it is going to do this sort of thing, I'd say the onus is on the type to clone if it thinks it appropriate.
from sharedb.
I closed this issue, but I still think there is a problem: ot-type with all behaviors satisfied may cause wrong data because of the current sharedb writeup, I need some time to check out
from sharedb.
Related Issues (20)
- How to pass options through to server? HOT 3
- Question client doc handleOp not debounce ?
- `TypeError Cannot read properties of null (reading 'callback')` when receiving subscribe response with no inflight subscribe HOT 4
- Feature suggestion: type accessors HOT 3
- Q: How multiple `Doc`s guarantee transactions? HOT 2
- Collaborative text field using react with debounce HOT 3
- How can I synchronize my article titles? HOT 6
- Avoid committing no-ops
- Feature Request: Support for Custom Type Projections in ShareDB HOT 3
- API Support for Presence Notifications HOT 6
- How do I implement custom messages, just like websockets HOT 2
- Consider Partysocket for Examples
- Access Control / Permissions HOT 2
- Example Proposal: Comments
- Messages artificially delayed when running `Backend` in the browser HOT 1
- how to reload/refresh ShareDB document? HOT 6
- Invalid op submitted. Op version newer than current snapshot HOT 4
- failed process file : failed send RangeError: Invalid string length HOT 4
- The doc links are broken
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 sharedb.