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

ProductService functions have different default values for scope parameter #18747

Open
timdk opened this issue Apr 19, 2024 · 0 comments
Open

Comments

@timdk
Copy link

timdk commented Apr 19, 2024

Describe the bug
When omitting the scope parameter to isLoading(), isSuccess() or hasError() it does not use the same scope as get()

Tell us the version of Spartacus

  • Library version: 2211.19

To Reproduce
Set up an observable to fetch a non-existing product like below.

const badProductCode = '9999';
combineLatest([
  this.productService.get(badProductCode),
  this.productService.hasError(badProductCode),
]).pipe(
  filter(([product, hasError]) => Boolean(product || (!product && hasError))),
).subscribe(([product, hasError]) => {
  console.log(product, hasError);
});

This never completes despite state being updated (see screenshot below). If the filter is removed it only emits undefined, false and never logs true for hasError()

ProductService uses DEFAULT_SCOPE for get() when it's omitted but '' for the other functions.

It can be resolved by using this.productService.hasError(badProductCode, DEFAULT_SCOPE) instead, but it's not immediately obvious.

It seems hasError(productCode) will never select a valid scope unless the user has intentionally passed '' as a scope when fetching a product.

Expected behavior
I would expect that omitting scope for the status functions uses the same DEFAULT_SCOPE constant as get().

Screenshots
The loading and error states are updated under the default entity in redux.

image

Desktop:

  • OS: All
  • Browser: All
  • Version: All

Additional context
Perhaps this is not a bug but more of an API quirk which could catch people out. Since '' is not a scope used or exported by ProductScope it seems unintentional.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant