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

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

Closed
TauPan opened this issue Feb 11, 2020 · 10 comments
Closed

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

TauPan opened this issue Feb 11, 2020 · 10 comments

Comments

@TauPan
Copy link
Contributor

TauPan commented Feb 11, 2020

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
Copy link
Contributor Author

TauPan commented Feb 11, 2020

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
Copy link
Contributor Author

TauPan commented Feb 11, 2020

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

@TauPan
Copy link
Contributor Author

TauPan commented Feb 11, 2020

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 TauPan closed this as completed Feb 11, 2020
@TauPan
Copy link
Contributor Author

TauPan commented Feb 11, 2020

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

@TauPan
Copy link
Contributor Author

TauPan commented Feb 11, 2020

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

@TauPan
Copy link
Contributor Author

TauPan commented Feb 12, 2020

(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
Copy link
Contributor Author

TauPan commented Feb 12, 2020

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 TauPan reopened this Feb 12, 2020
@TauPan
Copy link
Contributor Author

TauPan commented Feb 12, 2020

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

@TauPan
Copy link
Contributor Author

TauPan commented Feb 12, 2020

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.

TauPan added a commit to TauPan/yadcf that referenced this issue Feb 12, 2020
This is an obvious "fix" for my case and my app and the testcafe tests work.

I don't know why oLoadedState is null here, why the legacy api is apparently used and there are lots of other things I don't know.
vedmack added a commit that referenced this issue Aug 2, 2020
@vedmack
Copy link
Owner

vedmack commented Aug 2, 2020

fixed by #615

@vedmack vedmack closed this as completed Aug 2, 2020
vedmack added a commit that referenced this issue Aug 2, 2020
#614 - Uncaught TypeError: Cannot read property 'yadcfState' of null
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

No branches or pull requests

2 participants