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

Menubar: Custom locale config overwriting default untouched config properties #4270

Closed
nelson-antunes opened this issue Aug 14, 2023 · 4 comments
Assignees
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@nelson-antunes
Copy link

nelson-antunes commented Aug 14, 2023

Describe the bug

Menubar component with MenuItems throws "Uncaught TypeError: Cannot read properties of undefined (reading 'navigation')" when custom locale options are set for PrimeVue. This stops the component with the Menubar from rendering.

When debugging, I noticed that the custom locale configurations overwrote the whole default configuration object passed to the Menubar component in its render function, not only the changed properties.

Reproducer

https://codesandbox.io/s/musing-mopsa-vf6ddf?file=/src/main.js:4302-4314

PrimeVue version

3.29.0 - 3.32.0

Vue version

3.x

Language

ALL

Build / Runtime

Vite

Browser(s)

No response

Steps to reproduce the behavior

  1. Add any locale configuration in your PrimeVue installation/injection (main.js/ts)
  2. Add a Menubar component with a collection of MenuItems in your App

Expected behavior

No error

@nelson-antunes nelson-antunes added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Aug 14, 2023
@nelson-antunes nelson-antunes changed the title Component Name: Issue Title Menubar: Custom locale config overwriting other config properties Aug 14, 2023
@nelson-antunes nelson-antunes changed the title Menubar: Custom locale config overwriting other config properties Menubar: Custom locale config overwriting default config properties Aug 14, 2023
@nelson-antunes nelson-antunes changed the title Menubar: Custom locale config overwriting default config properties Menubar: Custom locale config overwriting default untouched config properties Aug 14, 2023
@nelson-antunes
Copy link
Author

Looking at the source code for PrimeVue install function (https://github.com/primefaces/primevue/blob/prod/components/lib/config/PrimeVue.js) we can see the problem is the use of spread (...) to set the default values for options. This won't work for nested objects, since the spreading is only ocurring in the first level of the object. Any nested object will be replaced as a whole by the new one passed inside the configuration object.

@tugcekucukoglu
Copy link
Member

Actually, you have already said the solution is using spread operator. Due to the config option being a reactive object, spread operation can be used also for its nested objects.

I have forked your example and made some changes: https://codesandbox.io/s/serverless-platform-5td2z9?file=/src/main.js:4291-4311

Thanks for your contribution!

@tugcekucukoglu tugcekucukoglu self-assigned this Aug 17, 2023
@tugcekucukoglu tugcekucukoglu added Type: Bug Issue contains a bug related to a specific component. Something about the component is not working and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Oct 31, 2023
@tugcekucukoglu tugcekucukoglu added this to the 3.39.0 milestone Oct 31, 2023
@YCdvll
Copy link

YCdvll commented Jan 27, 2024

Hello, it's the same problem with Rating component.
I add locale for calendar value and brake Rating component.

TypeError: Cannot read properties of undefined (reading 'star')

@ItriIbouanane
Copy link

Actually, you have already said the solution is using spread operator. Due to the config option being a reactive object, spread operation can be used also for its nested objects.

I have forked your example and made some changes: https://codesandbox.io/s/serverless-platform-5td2z9?file=/src/main.js:4291-4311

Thanks for your contribution!

What did you actually change ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

No branches or pull requests

4 participants