Skip to content

Meta is not set when storage item with migrations defined is initially created #1775

@absdjfh

Description

@absdjfh

Describe the bug

Given that there's an item definition with migrations (https://wxt.dev/storage), for example

const item = storage.defineItem<{
    value: string;
}>('local:data', {
    version: 2,
    migrations: {
        2: () => {
            // some code
        },
    },
});

Assume that user installed extension for the first time (i.e. there's no version 1 in their storage).

Setting any value to this item will store it without version metadata, which will lead to migration run when refreshing the page (if e.g. it's accessed in some content script).

This is usually incorrect cause migration code assumes data has old format, which never existed and was never set for a fresh install.

Reproduction

A PR with a failing test case: #1774

Steps to reproduce

No response

System Info

System:
    OS: Windows 11 10.0.26100
    CPU: (16) x64 Intel(R) Core(TM) i7-10700KF CPU @ 3.80GHz
    Memory: 34.40 GB / 63.87 GB
  Binaries:
    Node: 22.14.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.22 - C:\Program Files\nodejs\yarn.CMD
    npm: 11.4.2 - C:\Program Files\nodejs\npm.CMD
    pnpm: 9.1.4 - C:\Program Files\nodejs\pnpm.CMD
  Browsers:
    Edge: Chromium (133.0.3065.82)
    Internet Explorer: 11.0.26100.1882

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions