I am a new user, so I cannot “reply” to a user, but hopefully since wakecarter seems to know something about this bug, someone can tag them?
I thought I would explain what I found.
Looking at the code for the ServerManager.prepareResources() call (psychojs/ServerManager.js at main · psychopy/psychojs · GitHub) it looks like this from lines 505-519:
// convert those resources that are only a string to an object with name and path:
for (let r = 0; r < resources.length; ++r)
{
const resource = resources[r];
if (typeof resource === "string")
{
resources[r] = {
name: resource,
path: resource,
download: true
}
}
}
for (let { name, path, download } of resources)
{
...
However, when I look at the code for the “same” file loaded by my online Pavlovia experiment the code contains extra lines that seem related to “surveys”:
// pre-process the resources:
for (let r = 0; r < resources.length; ++r)
{
const resource = resources[r];
// convert those resources that are only a string to an object with name and path:
if (typeof resource === "string")
{
resources[r] = {
name: resource,
path: resource,
download: true
};
}
// deal with survey models: <--- THIS DOES NOT APPEAR IN GITHUB
if ("surveyId" in resource) <--- resource is still a string here. NEED TO USE resources[r]
{
// survey models can only be downloaded if the experiment is hosted on the pavlovia.org server:
if (this._psychoJS.config.environment !== ExperimentHandler.Environment.SERVER)
{
throw "survey models cannot be downloaded when the experiment is running locally";
}
// we add a .sid extension so _downloadResources knows what to download the associated
// survey model from the server
resources[r] = {
name: `${resource["surveyId"]}.sid`,
path: resource["surveyId"],
download: true
};
}
// deal with survey libraries:
...etc REMOVED EXTRA code...
}
for (let { name, path, download } of resources)
The bug is that this code:
// deal with survey models:
if ("surveyId" in resource)
Is using the in
operation on the original resource
variable…which is a string sometimes (such as when using a static component).
I think that all this extra “survey” stuff must have been added by someone (e.g. pavlovia?), as it is not found in the github PsychoJs code.
Some possible fixes for this bug would be:
- Move this special “survey” stuff into the
for
loop at L519 from the original code.
- I.e. leave the first for loop that converts string resources to object resources as-is. And then put this new for in the
for ... of
loop.
- Make sure it is using a
resource
variable that is an object (so that things like "surveyId" in resource
work). Alternatively, these checks could act on resources[r]
, which is definitely an object.
Anyway, I agree…I don’t think there is anyway to make the static component work until this bug is fixed.
Hopefully you might know who to ask to fix this?