DioxusLabs/dioxus · error

Selector that was created to match {} read after variant cha

Error message

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

What it means

A selector generated by the stores derive macro for a specific enum variant field was read after the store's active variant changed. The selector's lens still points at the old variant's field, which no longer exists in the current data, so reading it panics.

Source

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

    field_index: usize,
    field_count: usize,
) -> TokenStream2 {
    // When we map the field, we need to use either the field name for named fields or the index for unnamed fields.
    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,

View on GitHub (pinned to 24f6a829df)

Solutions

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

Strategy: type-guard

When it happens

Trigger: Thrown at packages/stores-macro/src/derive.rs:395 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/1b49ccf9ae183697. Report an issue: GitHub.