DioxusLabs/dioxus · error

Selector that was created to match {} written after variant

Error message

Selector that was created to match {} written after variant changed

What it means

A store selector bound to one enum variant's field was written after the store switched to a different variant. Writing through a stale lens would target a field that no longer exists, so the generated code guards with this panic.

Source

Thrown at packages/stores-macro/src/derive.rs:399

    let binding = function_name_from_field(field_index, field);
    let field_type = &field.ty;
    let pattern = if field.ident.is_none() {
        let before = (0..field_index).map(|_| quote!(_));
        let after = (field_index + 1..field_count).map(|_| quote!(_));
        quote!( ( #(#before,)* #binding, #(#after),* ) )
    } else {
        quote!( { #binding, .. })
    };
    // Each field gets its own reactive scope within the child based on the field's index
    let ordinal = LitInt::new(&field_index.to_string(), variant_name.span());
    quote! {
        let __map_field: fn(&#enum_name #ty_generics) -> &#field_type = |value| match value {
            #enum_name::#variant_name #pattern => #binding,
            _ => panic!("Selector that was created to match {} read after variant changed", stringify!(#variant_name)),
        };
        let __map_mut_field: fn(&mut #enum_name #ty_generics) -> &mut #field_type = |value| match value {
            #enum_name::#variant_name #pattern => #binding,
            _ => panic!("Selector that was created to match {} written after variant changed", stringify!(#variant_name)),
        };
        // Map the field into a child selector that tracks the field
        let scope = self.into_selector().child(#ordinal, __map_field, __map_mut_field);
        // Convert the selector into a store
        ::std::convert::Into::into(scope)
    }
}

// For enums, we derive two items:
// - An extension trait with methods to check if the store is a specific variant and a method
//   to access the field of that variant if there is only one field
// - A transposed version of the enum with all fields wrapped in stores
fn derive_store_enum(
    input: &DeriveInput,
    structure: &DataEnum,
    extension_trait_name: Ident,
    transposed_name: Ident,
    extension_generics: Generics,

View on GitHub (pinned to 24f6a829df)

Solutions

  1. A selector created for one enum variant was written after the variant changed. Re-create the selector after changing variants, or match before writing.
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at packages/stores-macro/src/derive.rs:399 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of DioxusLabs/dioxus@24f6a829df (2026-08-23). Data as JSON: /api/errors/a229aeb78f6d6472. Report an issue: GitHub.