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

DDFBRA-283 - Ensure v1/products/ is never called without an identifier #1597

Merged

Conversation

kasperbirch1
Copy link
Contributor

@kasperbirch1 kasperbirch1 commented Dec 13, 2024

Link to issue

https://reload.atlassian.net/browse/DDFBRA-283

Description

We have identified a recurring issue in the code where attempts are made to access the first element of an empty array (array[0]), which results in undefined.

This issue occurs across all articles where the identifier is an empty array.

Additionally, our TypeScript implementation requires the useGetV1ProductsIdentifier hook to receive a string. To satisfy TypeScript, we currently use || "", even though the hook is only activated when a value is present. However, this approach has inadvertently allowed errors to occur, and we have been uncertain about how to address this properly.

This change ensures that the || "" fallback in useGetV1ProductsIdentifier is never activated, effectively preventing the error from occurring.

Test

https://varnish.pr-1861.dpl-cms.dplplat01.dpl.reload.dk/search?q=hest

Select "articles" in the facet and make sure no drafts are created for v1/products/

Copy link
Contributor

@kasperg kasperg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 LGTM

I would appreciate if you get someone else to OK it as well.

@kasperbirch1 kasperbirch1 assigned spaceo and Adamik10 and unassigned kasperg Dec 16, 2024
Copy link
Contributor

@Adamik10 Adamik10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have one consideration :)

src/components/availability-label/availability-label.tsx Outdated Show resolved Hide resolved
We have identified a recurring issue in the code where attempts are made to access the first element of an empty array (`array[0]`), which results in `undefined`.

This issue occurs across all articles where the identifier is an empty array.

Additionally, our TypeScript implementation requires the `useGetV1ProductsIdentifier` hook to receive a string. To satisfy TypeScript, we currently use `|| ""`, even though the hook is only activated when a value is present. However, this approach has inadvertently allowed errors to occur, and we have been uncertain about how to address this properly.

This change ensures that the `|| ""` fallback in `useGetV1ProductsIdentifier` is never activated, effectively preventing the error from occurring.
@kasperbirch1 kasperbirch1 force-pushed the DDFBRA-283-publizon-adapter-kaldes-uden-identifier branch from ad617c8 to 460dc1c Compare December 16, 2024 08:47
@kasperbirch1 kasperbirch1 merged commit e1d4a97 into develop Dec 16, 2024
20 checks passed
@kasperbirch1 kasperbirch1 deleted the DDFBRA-283-publizon-adapter-kaldes-uden-identifier branch December 16, 2024 11:56
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

Successfully merging this pull request may close these issues.

4 participants