nicegui: Browser can't load page when table rows contain lists

Description

As @rohitsathish noticed on #2697, the following minimal example causes the app to freeze:

ui.table(columns=[{'name': 'A', 'label': 'A', 'field': 'A'}], rows=[{'A': [1, 2, 3]}])

It’s even more apparent when creating the table dynamically:

ui.button('Table', on_click=lambda: ui.table(columns=[{'name': 'A', 'label': 'A', 'field': 'A'}], rows=[{'A': [1, 2, 3]}]))

Somehow Vue and/or Quasar can’t handle the row content. But a minimal Quasar app works with the same data:

<html>
  <head>
    <link href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900|Material+Icons" rel="stylesheet" type="text/css" />
    <link href="https://cdn.jsdelivr.net/npm/quasar@2.15.1/dist/quasar.prod.css" rel="stylesheet" type="text/css" />
  </head>
  <body>
    <div id="q-app">
      <q-table :columns="[{'name': 'A','label': 'A','field': 'A'}]" :rows="[{'A': [1, 2, 3]}]" row-key="id" />
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.prod.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/quasar@2.15.1/dist/quasar.umd.prod.js"></script>
    <script>
      const app = Vue.createApp({ setup() { return {}; } });
      app.use(Quasar);
      app.mount("#q-app");
    </script>
  </body>
</html>

I’m out of ideas. Can anyone help to find out what’s going on? Thanks!

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 31 (16 by maintainers)

Commits related to this issue

Most upvoted comments

I wouldn’t mind taking a look in QTable implementation to determine if the logic / handling of rows is doing something obvious and open an issue based on what is found there.

This issue has been closed via PR #4775 and because I didn’t see a clear path forward. If you feel we should continue working on ui.table(rows=...), feel free to propose suggestions and I’ll re-open the thread.

I argued for splitting scenarios A and B mainly for two reasons:

  1. While calling ui.table(rows=rows) takes rows directly from user code, calling .from_pandas(df) implicitly converts the dataframe into row data. Like in #2697, problems seem to arise with the latter because the dataframe is kind of a black box.
  2. Checking rows is probably costly because we need to look into every single cell. Checking the dataframe inside .from_pandas(df), on the other hand, might be cheap if we only need to iterate over df.columns. Maybe it can be handled similarly to what we already do: https://github.com/zauberzeug/nicegui/blob/1c0aa64bd9de41950847f7a284f9604293db4308/nicegui/elements/table.py#L251-L269

I agree with your points mostly.

But where we diverge is, I’d reckon that ui.table is aso an API saying “just give me your data and we take care of the rest” as well.

So, also to achieve DRY principle, I believe we might as well add the warning to ui.table

P.S.: Having 2 APIs, one which warns, one which doesn’t, is also kinda mismatched and awkward as well.

Wow, thanks @xaptronic! In a nutshell (using NiceGUI’s Vue and Quasar versions):

<html>
  <head>
    <link href="https://fonts.googleapis.com/css?family=Roboto:400|Material+Icons" rel="stylesheet" type="text/css" />
    <link href="https://cdn.jsdelivr.net/npm/quasar@2.16.9/dist/quasar.prod.css" rel="stylesheet" type="text/css" />
  </head>
  <body>
    <div id="q-app"><test-table :rows="tableRows" /></div>
    <script src="https://cdn.jsdelivr.net/npm/vue@3.4.38/dist/vue.global.prod.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/quasar@2.16.9/dist/quasar.umd.prod.js"></script>
    <script>
      const TestTable = {
        template: `<q-table :columns="columns" :rows="clonedRows" />`, // :rows="rows" would cause the browser to freeze
        props: { rows: Array },
        data: () => ({ columns: [{ name: "id", label: "ID", field: "id" }] }),
        computed: {
          clonedRows() {
            return JSON.parse(JSON.stringify(this.rows));
          },
        },
      };
      const app = Vue.createApp({
        components: { TestTable },
        data: () => ({ tableRows: [{ id: [1, 2, 3] }] }),
      });
      app.use(Quasar);
      app.mount("#q-app");
    </script>
  </body>
</html>

Interestingly only arrays and date objects seem to be affected. Cloning all table rows is certainly not a viable solution, but an interesting insight nonetheless!

Does this qualify as a bug in Quasar or even Vue? We could try our luck and post it somewhere upstream.

@xaptronic managed to reproduce the infinite loop using just Vue and Quasar, no NiceGUI

https://github.com/zauberzeug/nicegui/pull/4694#issuecomment-2863966851

This can potentially rekindle this debugging effort, so I’m putting this here.

So you obviously can’t fight what you can’t see, right?

Image

https://stackoverflow.com/a/79072070

If you download Firefox, when the script grinds on the infinite loop, you can press “Debug Script” and that puts you in debugger.

@falkoschindler you may want to give this another shot, or perhaps we can do pre-processing to ensure that they are never lists to begin with?