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

QTree with children as object triggers error since 2.12 #15991

Closed
Tofandel opened this issue Jun 19, 2023 · 0 comments · Fixed by #15992
Closed

QTree with children as object triggers error since 2.12 #15991

Tofandel opened this issue Jun 19, 2023 · 0 comments · Fixed by #15992
Labels
area/components bug/1-repro-available A reproduction is available and needs to be confirmed. flavour/quasar-cli-webpack kind/bug 🐞 Qv2 🔝 Quasar v2 issues

Comments

@Tofandel
Copy link
Contributor

Tofandel commented Jun 19, 2023

What happened?

Since 2.12.0, specifically this commit c6242ba#diff-387b9b62424fed6c9add037b377c07e02f3deca0d50edeb2a415defd12f0e9bbR143

A QTree throws error when nodes have an empty object instead of an empty array

<QTree 
              label-key="name"
              node-key="id"
              :nodes="[{id: 1, name: 'Test', children: {}}]"/>

This is a problem because in PHP json serialization creates objects instead of arrays when your array is empty, which when retrieved from API and used in Quasar, triggers this error

json_encode(['nodes' => [['id' => 1, 'name' => 'Test', 'children' => []]]]) 
=> {"nodes": [{"id": 1, "name": "Test", "children": {}}]}

What did you expect to happen?

No error to be thrown, it should handle the fact that children is not an array

Reproduction URL

https://codepen.io/Tofandel/pen/RwqRwQY

How to reproduce?

  1. Go to reproduction link
  2. Page is blank and check console for error

Flavour

Quasar CLI with Webpack (@quasar/cli | @quasar/app-webpack)

Additional context

Changing from .length > 0 to .length !== 0 is not equivalent because ({}).length is undefined

([]).length > 0
false
({}).length > 0
false
([]).length !== 0
false
({}).length !== 0
true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/components bug/1-repro-available A reproduction is available and needs to be confirmed. flavour/quasar-cli-webpack kind/bug 🐞 Qv2 🔝 Quasar v2 issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant