Skip to content

fix: archive layers no layer group references - #1087

Draft
AKnassa wants to merge 2 commits into
google:masterfrom
AKnassa:rocky/issue-932-archive-unreferenced-layers
Draft

fix: archive layers no layer group references#1087
AKnassa wants to merge 2 commits into
google:masterfrom
AKnassa:rocky/issue-932-archive-unreferenced-layers

Conversation

@AKnassa

@AKnassa AKnassa commented Jul 28, 2026

Copy link
Copy Markdown

Fixes #932

What this does

A layer that is not displayed by any layer group is now archived instead of being thrown away.

Why

If a state defines a layer but uses a custom layout whose viewers do not list it, the layer used to disappear when the state was loaded. Archiving keeps it, which is what "archived": true in the state would have produced, and it matches what the layer drag-and-drop code already does for layers that end up in no layer group. This follows the suggestion in the issue thread.

What changed

  • Layers referenced only by the root layer manager are archived rather than deleted.
  • Temporary drag-and-drop placeholders are still removed, since those are not layers the user asked for.

Worth a reviewer's attention

This also applies when the last layer group referencing a layer goes away, so removing a layer group now archives its layers rather than deleting them.

How to see it

Load a state with a single layer and a layout such as {"type":"row","children":[{"type":"viewer","layers":[]}]}. Before this change the layer vanished; now it appears in the layer list as archived. New unit tests in src/layer/index.spec.ts cover this along with the drag-target and already-archived cases.

AKnassa added 2 commits July 27, 2026 00:15
`LayerManager.removeLayersWithSingleRef` discarded every layer held only
by the root layer manager.  A state that defines a layer but uses a
custom layout whose viewers do not list it — `{"type":"row","children":
[{"type":"viewer","layers":[]}]}` — leaves exactly such a layer, so the
layer was silently dropped on load.  Simple layouts are unaffected
because they pin the root manager directly, which disables the sweep.

Archive those layers instead of discarding them, which is what
`archived: true` in the state would have produced and what the layer
drag-and-drop code already does for layers that end up in no layer group.
Layers with no user layer are transient drag targets rather than
something the user asked for, so they are still removed.

Note this also applies when the last layer group referencing a layer goes
away, so removing a layer group now archives its layers rather than
deleting them.

Fixes google#932
A layer referenced by a layer group must be left alone by the sweep, and
must become archived rather than deleted once the group's reference is
released.  Breaking the `refCount === 1` guard is caught only by this
test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Layers not marked as archived that are not part of any layer group don't get auto archived on state creation

1 participant