Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timing issue when using Interface-effects #846

Open
Anders2303 opened this issue Jan 14, 2025 · 1 comment
Open

Timing issue when using Interface-effects #846

Anders2303 opened this issue Jan 14, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@Anders2303
Copy link
Collaborator

Noticed a case where my query is firing between two interface-effects, causing the query to be run with the wrong values and failing.

Need to observe this more to figure exactly what causes is, but it might be some timing thing related to one of the interface-atoms being from a query affected by the first.

export const settingsToViewInterfaceEffects: InterfaceEffects<SettingsToViewInterface> = [
    (getInterfaceValue, setAtomValue) => {
        // ! Likely relevant: the header here is also dependent on field. The atom is a "fix-up" selection from a async list of the field's available wellbores
        const wellboreUuid = getInterfaceValue("wellboreHeader");
        setAtomValue(wellboreHeaderAtom, wellboreUuid);
    },
    (getInterfaceValue, setAtomValue) => {
        const selectedField = getInterfaceValue("selectedField");
        setAtomValue(selectedFieldIdentAtom, selectedField);
    },
];

For this, when swapping field - from DROGON to FIELD_A - a dependent query I have in the module's view code is being fired with the parameters field=DROGON&wellbore_uuid=some_wellbore_id, but it should be field=FIELD_A&wellbore_uuid=some_wellbore_id. So only the wellbore UUID atom has updated, according to tanstack.

Also, worth nothing:

  • Both effect functions are being run
    • As far as I can gleam from the console, both effects are both run before the xhr request is being started, but could be that tanstack is picking the values earlier than that
  • The system never runs a query with the correct values.
  • If changing the wellbore-header after the fact, a correct query is fired
@Anders2303 Anders2303 added the bug Something isn't working label Jan 14, 2025
@Anders2303
Copy link
Collaborator Author

It seems that what's happening, is that Jotai always recomputes all derived atoms between each setAtomValue call. Does this not mean that every interface-effect in the system potentially runs multiple uneccessary recomputations? We might need to change how the interface effects are handled if so...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant