Ramonda

context-consumed-above-its-provider

This fails the run. Where it is wrong about your code, // ramonda-check-ignore <reason> on the line says so, and the reason is printed on every run.

Reported when a component consumes a context on a line above the Provider that publishes it, so the consumer reads an ancestor's value.

The framework reports the same fault while running, as RMD057 — but only once the line actually runs. This is the same fault proved from the source instead.

A consumer resolves its channel ONCE, when it is constructed, and hooks are constructed in field-declaration order. So a consumer above the provider on its own component looked before that provider existed, and reads the nearest one on an ANCESTOR instead — or the context's default, if there is none.

If this component's own value was meant, read it through the PROVIDER hook rather than a consumer: a Provider reads as well as provides, so this.theme.color where theme is the Provider always means this component's value and does not depend on the order. Moving the provider above the consumer works too, and leaves the answer resting on which line is first.

If the value from ABOVE was meant — reading the outer theme to derive an inner one — then this is that arrangement working, and the order it needs is the order it has. Nothing else in the source says which of the two it is, which is why this is reported rather than failed.

The other order is not reported: this.use(QueryClientProvider) followed by this.use(Query, …) is mount-a-client-then-query-on-it, and that is what the packages do.

A BASE CLASS is part of the order. Its fields initialise first, so a consumer inherited from a base is always above a provider mounted here, however the two files are laid out.

Next