Seems like there’s a lot of confusion around this issue, and why it exists. Let’s dive into the details to determine the actual cause.
The problem
Stacks externals are being copied between projects.
Why is this happening
@joeworkman is on the right track with explanation of memory space being shared between all open projects. However, RapidWeaver doesn’t allocate this, Stacks is responsible for allocating and managing its own memory.
Further to this, RapidWeaver doesn’t have any control over the content that is saved from a plugin. RapidWeaver requests raw data to be saved, and persists it to a file on your hard drive. It’s also responsible for reading the raw data and passing it to the plugin during load. RapidWeaver itself doesn’t have any knowledge of the contents of this data.
We don’t have access to the Stacks source code so the below is a best guess based on the problem you’re seeing.
To the best of our knowledge, Stacks is using something called a singleton class to store project data. The singleton design pattern restricts the instantiation of a class to a single object. This means that only one instance of the class can be created throughout the entire program and is shared between all open projects.
It’s absolutely fine to do this, however the developer should exercise extreme caution when doing so to prevent unexpected or hard to fix bugs.
Say we have a singleton class called FileStore which is responsible for storing a list of paths to files the project uses. After opening gallery.rwc
, the FileStore could look like this.
[
~/Desktop/photos/image1.jpeg,
~/Desktop/photos/image2.jpeg
]
Lets open another project, blog.rwc
. This project also contains files which need to be added to the FileStore. Here’s how the FileStore could look after opening the blog project.
[
~/Desktop/photos/image1.jpeg,
~/Desktop/photos/image2.jpeg,
~/Desktop/dogs/doberman.jpeg,
~/Desktop/dogs/labrador.jpeg
]
You can see how the FileStore has become polluted with content from both open projects. When saving the gallery.rwc
project file, there’s no way to identify which files in FileStore are used in which project.
Fortunately, the way to solve this is quite trivial, the FileStore should index files based on the document.
{
“gallery.rwc”: [
~/Desktop/photos/image1.jpeg,
~/Desktop/photos/image2.jpeg
],
“blog.rwc”: [
~/Desktop/dogs/doberman.jpeg,
~/Desktop/dogs/labrador.jpeg
]
}
Now when a project is saved, it’s simple to find which files are being used by which project.
Summary
We believe Stacks is using this method to index Externals. We also believe Stacks isn’t keeping track of the Externals used within a project. So when a project is saved, all Externals are copied into the project file just in case they’re being used.
Unfortunately there’s absolutely nothing we can do in RapidWeaver to address this issue. It’s entirely the responsibility of the plugin to manage the data it stores in the project file.
I really wish we could fix this issue, but it’s out of our control. I’m afraid it’s very likely this will also be a problem in Stacks Pro until it’s fixed.