storyblok / storyblok-js-client

Universal JavaScript client for Storyblok's API
MIT License
129 stars 87 forks source link

Fix resolveNestedRelations disabling during StoryblokClient init #844

Open edvinasjurele opened 4 months ago

edvinasjurele commented 4 months ago

Expected Behavior

Storyblok client is possible to initialize with resolveNestedRelations disabled.

Current Behavior

Initializing the Storyblok client with resolveNestedRelations flag disabled, does not correctly set the initial value

const Storyblok = new StoryblokClient({
  accessToken: '<TOKEN>',
  resolveNestedRelations: false,
});

Temporary workaround

Manually set flag AFTER the storyblok client initialization.

Storyblok.resolveNestedRelations = false;

Steps to Reproduce

https://runkit.com/embed/xx23fbgocz7c

Screenshot 2024-07-26 at 15 27 02

Potential defect

When passing resolveNestedRelations: false, as part of init object, the resolveNestedRelations should be set to false, but due to this.resolveNestedRelations = config.resolveNestedRelations || true in the https://github.com/storyblok/storyblok-js-client/blob/d04da2e201755a175aa6702db2cd485e145f5019/src/index.ts#L150 it is set to true for all falsey values including FALSE itself, as "false || true => true".

We might replace || with ??

image
alvarosabu commented 2 months ago

Hi @edvinasjurele thanks for opening this issue. I think I understand the issue, I tried to open the reproduction tho and it's broken (gives me an error) could you please add a working reproduction please?

edvinasjurele commented 2 months ago

Hi @alvarosabu, hm, the repro link works fine for me 🤔 but here is another repro: https://stackblitz.com/edit/stackblitz-starters-5wkmv5?file=index.js

alvarosabu commented 2 months ago

Hi @edvinasjurele thanks for providing another reproduction, I dont know what happened but I also managed to run the first one, I like the runkit is really helpful.

Let me take care of it.