Background
I heavily utilize the setPluginData
function on the root node to store messages and localized variants within the Parrot Plugin. This works incredibly well - even multiplayer edits work like a charm. Great job, Figma! However, I’ve encountered a problem during rigorous sync testing:
Steps to reproduce
If a user is offline and modifies an entry using the setPluginData
function, then comes back online after a (possibly extended) period, their changed plugin data will overwrite all entries - not just the ones they modified.
To illustrate, let’s say UserA opens the plugin and the plugin executes:
figma.root.setPluginData('a', 'I was set by UserA');
Meanwhile, UserB, who is offline, opens the plugin and runs:
figma.root.setPluginData('b', 'I was set by UserB');
When UserB reconnects online, a call to figma.root.getPluginDataKeys()
will yield:
['b']
However, the expected result are:
['a', 'b']
This inconsistency occurs regardless of when UserA or UserB invokes the setPluginData
function.
I expected that each plugin data key would be integrated separately.
Please note that I cannot confirm if this behavior is replicated between different plugins or when using shared plugin data, although I suspect it might be.
Problem
The current behavior could lead to data loss, as there seems to be no way (?) to intercept the merging of changes.
Workarounds
There are a couple of potential workarounds:
- To circumvent this issue, one could generate a node on the initial page per user and consolidate all the information on these auxiliary nodes. Modifications made on different nodes are merged as expected. The drawback, of course, is that these nodes might be inadvertently deleted, resulting in data loss.
- Alternatively, storing data in Figma string variables instead of fields is possible. Nonetheless, this approach comes with its own disadvantages: users can alter the data within the UI, and there isn’t an apparent means to monitor variable changes (?).
Questions
I have a few questions regarding this scenario:
- Is the observed behavior considered the intended outcome? Could we receive an explanation of the underlying mechanism?
- Is there a method to determine a user’s offline state in order to prevent certain operations?
- Can similar conflicts arise between different plugins?
- Does this behavior hold true for shared plugin data as well?
Thank you for your support.
Best regards, Martin