SemanticMediaWiki / SemanticResultFormats

Provides additional visualizations (result formats) for Semantic MediaWiki
https://www.semantic-mediawiki.org/wiki/Extension:Semantic_Result_Formats
Other
45 stars 75 forks source link

[Datatables] Cannot read properties of null (reading 'formattedOptions') #807

Closed alistair3149 closed 3 months ago

alistair3149 commented 5 months ago

Setup

Issue

Datatables only render once or twice after page edit or purge or SMW refresh. Otherwise it fails to initialize and does not render and return the following errors:

jQuery.Deferred exception: Cannot read properties of null (reading 'formattedOptions') TypeError: Cannot read properties of null (reading 'formattedOptions')
  at srf.formats.datatables.init (<anonymous>:335:120)

Uncaught TypeError: Cannot read properties of null (reading 'formattedOptions')
  at srf.formats.datatables.init (<anonymous>:335:120)

Upon further investigation, on the instances that datatable does not render, the datatable data is not saved to mw.config at all. Normally, datatable data is saved to mw.config under the key smw-{$id}. However, the key does not exist in those instances.

You can see a live demo here: https://starcitizen.tools/User:Alistair3149/sandbox/datatable

Expected result: Page is loaded -> Datatable loading indicator appears -> Datatable loading indicator disappears -> Datatable is rendered

Observed result: Page is loaded -> Datatable loading indicator appears -> Datatable loading indicator disappears -> Nothing

alistair3149 commented 3 months ago

Upon further investigation, the inline script that set the smw-{$id}:

mw.config.set({
  "smw-65f9cce600e36": "..."
};

had a cached nonce after the initial edit and didn't update afterwards, resulting in a CSP violation which prevents the value being set.

Since WMF have already removed nonce support upstream in 1.41, this issue can be safely ignored.