-
-
Notifications
You must be signed in to change notification settings - Fork 125
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
Prevent one client syncing private attributes with other clients. #37
base: master
Are you sure you want to change the base?
Conversation
….hasOwnProperty() will cause error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this @fuzhuyi ,
The PR looks fine, but could you please make sure that npm test
still works?
src/plugins/sync-plugin.js
Outdated
@@ -711,7 +745,7 @@ export const updateYFragment = (y, yDomFragment, pNode, mapping) => { | |||
} | |||
// remove all keys that are no longer in pAttrs | |||
for (const key in yDomAttrs) { | |||
if (pAttrs[key] === undefined) { | |||
if (pAttrs.hasOwnProperties(key) && pAttrs[key] === undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition can't be true. So you are basically forcing that dom attributes are never deleted. This is probably why the tests fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of this condition?
@@ -213,6 +215,20 @@ export class ProsemirrorBinding { | |||
yXmlFragment.observeDeep(this._observeFunction) | |||
|
|||
this._domSelectionInView = null | |||
|
|||
if (typeof getFallbackNode === 'function') { | |||
const fallbackNode = getFallbackNode() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a lot of code. Do you think it would suffice to simply store the name of the fallback node?
} | ||
|
||
let node | ||
if (typeof getFallbackNode === 'function') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified to a simple if/else construct.
@@ -711,7 +776,7 @@ export const updateYFragment = (y, yDomFragment, pNode, mapping) => { | |||
} | |||
// remove all keys that are no longer in pAttrs | |||
for (const key in yDomAttrs) { | |||
if (pAttrs[key] === undefined) { | |||
if (key in pAttrs && pAttrs[key] === undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see my comment above. This condition can never be true.
@@ -757,7 +822,13 @@ export const updateYFragment = (y, yDomFragment, pNode, mapping) => { | |||
const leftP = pChildren[left] | |||
const rightY = yChildren[yChildCnt - right - 1] | |||
const rightP = pChildren[pChildCnt - right - 1] | |||
if (leftY instanceof Y.XmlText && leftP instanceof Array) { | |||
if (!(leftP instanceof Array) && isFallbackNode && isFallbackNode(leftP)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be simplified to simply: if (isFallbackNode(leftP)) {..}
if (!(leftP instanceof Array) && isFallbackNode && isFallbackNode(leftP)) { | ||
if (mapping.get(leftY) !== leftP) { | ||
yDomFragment.delete(left, 1) | ||
yDomFragment.insert(left, /** @type Array{Y.XmlFragment} */ [leftY]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really see why it is necessary to delete and insert the same node. Also, it is not possible to insert the same shared type (leftY
) again in the document. Even if it has been deleted before.
} else { | ||
Y.typeListToArraySnapshot(el, new Y.Snapshot(prevSnapshot.ds, snapshot.sv)).forEach(createChildren) | ||
let isKnownNode = !!schema.nodes[el.nodeName] | ||
if (isKnownNode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could simply do if (schema.nodes[el.nodeName])
.
But you could simplify this even more by doing the following right at the beginning of createNodeFromYElement
.
if (!schema.nodes[el.nodeName]) {
let fallbackNode = schema.node(el.nodeName, attrs, children);
mapping.set(el, fallbackNode);
return fallbackNode
}
Define yPrivate attribute in prosemirror schema, and prevent one client syncing the private attributes with other clients.