ID:2961371
 
Resolved
Writing to byondStorage now properly calls sync() on the appropriate storage item in any other browser windows for the same Dream Seeker session. Note that this will not synchronize across separate DS sessions that are both running.
BYOND Version:516.1651
Operating System:Windows 11 Pro 64-bit
Web Browser:Chrome 131.0.0.0
Applies to:Dream Seeker
Status: Resolved (516.1652)

This issue has been resolved.
Descriptive Problem Summary:
ByondStorage seems to only read from file during initialization. From that point on it seems to only operate off of memory, and it does not synchronize this memory between different windows. Instead, each window will happily trample changes any other window has made to ByondStorage.

Of note, if the solution is simply to always synchronize from file when reading/writing and that is less performant, it could just be an function call from the user to call that sync function, but it sounded like there was already some mechanism that was supposed to keep it in sync automatically.

Numbered Steps to Reproduce Problem:
1. Launch test project
2. Press Increment and Save a few times
This will update a javascript var and write that to storage
3. Press Read and Refresh on the other window
This will give you the value of the current dataKey selection from the state when you launched the project instead of the value that the first window wrote.

Feel free to tinker with the form and or view the Drathek.Testing.json file in your Documents\BYOND\browserstorage folder.

Code Snippet (if applicable) to Reproduce Problem:
/world
fps = 25
icon_size = 32
view = 6
hub = "Drathek.Testing"
visibility = 0

var/data = {"
<html>
<head>
<script type='text/javascript'>
class HubStorageBackend {
async get(key) {
const value = await window.hubStorage.getItem(key);
if (typeof value === "string") {
return JSON.parse(value);
}
}

async set(key, value) {
window.hubStorage.setItem(key, JSON.stringify(value));
}

async remove(key) {
window.hubStorage.removeItem(key);
}

async clear() {
window.hubStorage.clear();
}
};

let storage = new HubStorageBackend();
let localValue = 0;

const getSelectedDataKey = function() {
let key1Radio = document.getElementById("dataKey1Radio");
if (key1Radio.checked) {
return "dataKey1";
}
return "dataKey2";
};

const incrementAndSave = function() {
localValue++;
storage.set(getSelectedDataKey(), localValue);
readAndRefresh();
};

const readAndRefresh = function() {
let localField = document.getElementById("localField");
let storageField = document.getElementById("storageField");
storage.get(getSelectedDataKey()).then((val) => {
localField.value = localValue;
storageField.value = val;
});
};
</script>
</head>
<body>
<input type="radio" id="dataKey1Radio" name="dataKey" value="dataKey1" checked>
<label for="dataKey1Radio">dataKey1</label><br>
<input type="radio" id="dataKey2Radio" name="dataKey" value="dataKey2">
<label for="dataKey2Radio">dataKey2</label><br>

<label for="localField">Local value (read only)</label><br>
<input type="text" id="localField" readonly value="0" style="width:100%"><br>
<label for="storageField">Storage value (read only)</label><br>
<input type="text" id="storageField" readonly value="This value will be updated with what is read from storage after either button press." style="width:100%"><br>

<input type="button" onclick="incrementAndSave()" value="Increment and Save">
<input type="button" onclick="readAndRefresh()" value="Read and Refresh"><br>

<div>Both windows even if they modify the same key have a different idea of what the byond storage currently is. As in they only read from file during intialization but otherwise only operate off of memory.</div>
</body>
</html>
"}


/client/New(TopicData)
..()
winset(src, "", "browser-options=byondstorage,find,devtools,refresh")
src << browse(data, "window=browser1")
src << browse(data, "window=browser2")


menu "menu"
elem
name = "&Quit"
command = ".quit"
category = "&File"
saved-params = "is-checked"


window "default"
elem "default"
type = MAIN
pos = 291,0
size = 640x480
anchor1 = -1,-1
anchor2 = -1,-1
background-color = none
is-default = true
saved-params = "pos;size;is-minimized;is-maximized"
macro = "macro"
menu = "menu"
outer-size = 656x558
outer-pos = 291,0
inner-pos = 8,51
screen-size = 2560x1392
elem "browser1"
type = BROWSER
pos = 0,0
size = 640x480
anchor1 = 0,0
anchor2 = 100,100
background-color = none
saved-params = ""

window "window1"
elem "window1"
type = MAIN
pos = 291,0
size = 640x480
anchor1 = -1,-1
anchor2 = -1,-1
background-color = none
saved-params = "pos;size;is-minimized;is-maximized"
outer-size = 656x538
outer-pos = 291,0
inner-pos = 8,31
screen-size = 2560x1392
elem "browser2"
type = BROWSER
pos = 0,0
size = 640x480
anchor1 = 0,0
anchor2 = 100,100
background-color = none
saved-params = ""


https://discord.com/channels/725444629172060262/ 725458744711839873/1331892680460079116

Expected Results:
Writing say the value 7 to dataKey1 should result in both windows reading dataKey1 as the value 7.

Actual Results:
Writing say the value 7 to dataKey1 will only result in the window that wrote it to read it as 7. The other window will read it as what it was either from its local window memory (likely whatever it was in file during launch).

Does the problem occur:
Every time? Or how often? Always
In other games? Yes
In other user accounts? Yes
On other computers? Yes

When does the problem NOT occur?
Trident implementation of storage.

Did the problem NOT occur in any earlier versions? If so, what was the last version that worked? (Visit http://www.byond.com/download/build to download old versions for testing.) Same behavior on 516.1648 so likely applies to all public 516 versions.

Workarounds:
Only ever write to ByondStorage using one window.
You incorrectly marked this as a webclient bug. It's a Dream Seeker bug, nothing to do with the webclient.
Lummox JR resolved issue with message:
Writing to byondStorage now properly calls sync() on the appropriate storage item in any other browser windows for the same Dream Seeker session. Note that this will not synchronize across separate DS sessions that are both running.

Login to reply.