Effect Execution Order
The knowledge sources do not explicitly guarantee a specific ordering between multiple effects created in the same context. What is documented is:
- "View effects" run before their corresponding component is checked during change detection.
- "Root effects" run prior to all components being checked.
- Effects always execute asynchronously, during the change detection process. [Angular Effects Guide]
There is no documented guarantee that one effect() call will always run before another effect() call defined after it.
The Recommended Angular Approach
More importantly, your design has a conceptual issue that the Angular docs directly address:
Avoid using effects for propagation of state changes. Instead, use computed signals to model state that depends on other state. [Angular Effects Guide]
The docs also note that effects are appropriate for keeping data in sync with storage (e.g., localStorage), but the read-from-storage part (initialization) is better handled outside of an effect entirely — for example, in the constructor or during service initialization.
Here's the Angular-idiomatic pattern based on the knowledge sources:
const resolvedKey = computed(() => this.name() + '-key');
const stored = localStorage.getItem(resolvedKey());
const state = signal(stored ? JSON.parse(stored) : defaultValue);
effect(() => {
localStorage.setItem(resolvedKey(), JSON.stringify(state()));
});