vedmack / yadcf

Yet Another DataTables Column Filter (yadcf)
http://yadcf-showcase.appspot.com/
MIT License
732 stars 284 forks source link

Uncaught TypeError: Cannot read property 'yadcfState' of null #614

Closed TauPan closed 4 years ago

TauPan commented 4 years ago

I see the following with 0.9.4-beta.28 (via yarn).

jquery.dataTables.yadcf.js:4275 Uncaught TypeError: Cannot read property 'yadcfState' of null
    at saveTextKeyUpState (jquery.dataTables.yadcf.js:4275)
    at keyUp (jquery.dataTables.yadcf.js:4261)
    at jquery.dataTables.yadcf.js:4269
    at jquery.dataTables.yadcf.js:901

This happens when I type into a column search field.

This is defined as:

      {column_number: 0,
       filter_type: 'text',
       filter_default_label: 'Filter Vuln IDs',
       regex_check_box: true,
       filter_delay: 1500
      },

Not sure if relevant, the datatables column has a render property:

      {
        data: 'vulnerability__vuln_id',
        render: (data, _type, row, _meta) =>
          `
<a href="${location.origin}/airshield/findings/${row.id}/">
${data}
</a>
`
      },

Sorry, if this is not a bug in yadcf.

TauPan commented 4 years ago

I just upgraded to beta.40 by hand (28 is available on yarn, so I preferred that earlier) and can reproduce the behaviour there as well.

TauPan commented 4 years ago

In fact, the error disappears when I remove the render function.

TauPan commented 4 years ago

Uhm, when I reinstall (beta 28 or 40, doesn't matter) this behaviour disappears. Maybe I had the wrong beta (possibly 5, from npm) installed here.

TauPan commented 4 years ago

Ugh, it just reappeared again, unfortunately. I'll see what actually reproduces this on my part.

TauPan commented 4 years ago

testcafe reproduces this reliably, but I've seen this error in the actual browser console as well... still investigating...

TauPan commented 4 years ago

(I hope you don't mind if I'm keeping notes on this closed issue. I'll reopen it when I'm sure that it's a bug in yadcf as opposed to my own code or testcafe. Testcafe is probably out of the picture because I could at some point reproduce it in the browser by hand.)

Firefox (Quantum 68.4.2esr (64-Bit)) gives a different error (the above was with chromium ( 80.0.3987.87 (openSUSE Build) (64-Bit))):

JavaScript error details:
oTable.fnSettings(...).oLoadedState is null:
saveTextKeyUpState@http://127.0.0.1:8003/airshield/static/js/airshield.bundle.js:40200:68
keyUp@http://127.0.0.1:8003/airshield/static/js/airshield.bundle.js:40186:5
textKeyUP/<@http://127.0.0.1:8003/airshield/static/js/airshield.bundle.js:40194:6
airshield</</</yadcf</yadcfDelay</</timer<@http://127.0.0.1:8003/airshield/static/js/airshield.bundle.js:36860:6

I think that's because firefox doesn't correctly parse the source-map (no idea why). From the line numbers, it looks like it's this function:

        function saveTextKeyUpState(oTable, table_selector_jq_friendly, column_number, regex_check_box, null_checked, exclude) {
            if (oTable.fnSettings().oFeatures.bStateSave === true && oTable.fnSettings().oLoadedState.yadcfState) {
                if (oTable.fnSettings().oLoadedState.yadcfState !== undefined && oTable.fnSettings().oLoadedState.yadcfState[table_selector_jq_friendly] !== undefined) {
                    oTable.fnSettings().oLoadedState.yadcfState[table_selector_jq_friendly][column_number] = {
                        regex_check_box: regex_check_box,
                        null_checked: null_checked,
                        exclude_checked: exclude
                    };
                } else {
                    yadcfState = {};
                    yadcfState[table_selector_jq_friendly] = [];
                    yadcfState[table_selector_jq_friendly][column_number] = {
                        regex_check_box: regex_check_box,
                        exclude_checked: exclude,
                        null_checked: null_checked
                    };
                    oTable.fnSettings().oLoadedState.yadcfState = yadcfState;
                }
                oTable.fnSettings().oApi._fnSaveState(oTable.fnSettings());
            }
        }

The problem in chromium is in the same line of code, the phrasing is just different

JavaScript error details:                                                                                                                                                     
TypeError: Cannot read property 'yadcfState' of null                                                                                                                          
    at saveTextKeyUpState (http://127.0.0.1:8003/airshield/static/js/airshield.bundle.js:40200:93)                                                                            
    at keyUp (http://127.0.0.1:8003/airshield/static/js/airshield.bundle.js:40186:5)                                                                                          
    at http://127.0.0.1:8003/airshield/static/js/airshield.bundle.js:40194:6                                                                                                  
    at http://127.0.0.1:8003/airshield/static/js/airshield.bundle.js:36860:6

So for some reason oTable.fnSettings() returns a null value. Edit: Actually, just oLoadedState is null in the returned object.

From the way it behaves (sometimes the error is thrown after the click, sometimes on keyboard input) I would suspect it's related to timing.

TauPan commented 4 years ago

I'm confused now. fnSettings is legacy Datatables api isn't it? There's a function getSettingsObjFromTable which smartly dispatches to get the right thing, but in several parts of the code, fnSettings is still used.

I'm using datatables 1.10.19 (could try upgrading to 1.10.20 if that helps).

TauPan commented 4 years ago

(Not sure that this is a bug in yadcf yet, but maybe you can clarify things.)

TauPan commented 4 years ago

I'm using datatables 1.10.19 (could try upgrading to 1.10.20 if that helps).

Unfortunately the minor datatables upgrade does not help.

vedmack commented 4 years ago

fixed by https://github.com/vedmack/yadcf/pull/615