Uploading attachment - TypeError: Cannot read properties of null (reading 'textContent')

Hey @mleduc , thank you for your reply (as always!)

  • I’ve done a cookie delete aswell, yes! ()attempted another cache renew)
  • Issue persists in ‘private mode’ browsing also
    image
  • to triple check I attempted to upload from an entirely fresh environment, that had the same result (99.9% sure it’s not a browser/cache/cookie issue)
  • Added links to the server logs

Catalina - Pastebin.com
localhost acces log - Pastebin.com

Thanks @Wardenburg,

  • your pastebin link looks broken
  • did you also notice errors on the browser console?
1 Like

Apologies, pastebin deleted them because I wasnt registered (I Guess)

new links:

Catalina - Pastebin.com
localhost acces log - Pastebin.com

Attached a network log of the error (it’s in .har format)
kennis.wardenburg.nl.txt (18.7 KB)

console has one error

image

Can you tell me if you can find elements with the following ids in your page: attachment-validation-filesize-configuration or attachment-validation-mimetypes-configuration? And if they exists, show me their content.

If that’s the case, it could mean that XWiki.Attachment.Validation.Code.MimetypeValidation or XWiki.Attachment.Validation.Code.FileSizeValidation UIXs are not correctly loaded.

1 Like

Hey mledic, when you say ‘ids in your page’ do you mean as element on the page itself or as an event?

I’m not entirely sure how to look for what you’re asking, I did the following: when I look under Sources and search through ‘all files’ I get the following result:

Searching for: " attachment-validation-filesize-configuration ":
1 result: ( https://xwikiurl.nl/jsx/XWiki/Attachment/Validation/Code/FileSizeValidation?language=nl&docVersion=1.1 )

define("attachment-validation-filesize-messages",{prefix:"attachment.validation.filesize.",keys:["errorMessage"]});
require(["jquery","xwiki-l10n!attachment-validation-filesize-messages","xwiki-events-bridge"],(d,g)=>{function f(c){if(!+c)return"0 bytes";const a=Math.floor(Math.log(c)/Math.log(1024));return`${parseFloat((c/Math.pow(1024,a)).toFixed(2))}${" bytes;Kb;Mb;Gb;Tb;Pb;Eb;Zb;Yb".split(";")[a]}`}const e={};d(document).on("xwiki:actions:beforeUpload",(c,a)=>{if(a.documentReference){e[a.documentReference]||d.ajax({url:(new XWiki.Document(XWiki.Model.resolve("XWiki.Attachment.Validation.Code.FileSizeValidation",
XWiki.EntityType.DOCUMENT))).getURL("get",d.param({outputSyntax:"plain",documentReference:a.documentReference})),async:!1,method:"GET",success:function(h){e[a.documentReference]=h}});var b=e[a.documentReference]}else b=document.getElementById("attachment-validation-filesize-configuration").textContent;b=JSON.parse(b).maxFileSize;a.file.size>b&&(b=g.get("errorMessage",a.file.name,f(a.file.size),f(b)),new XWiki.widgets.Notification(b,"error"),c.preventDefault())})});

Searching for: " attachment-validation-mimetypes-configuration ":

1 result: ( https://xwikiurl.nl/jsx/XWiki/Attachment/Validation/Code/MimetypeValidation?language=nl&docVersion=1.1 )

define("attachment-validation-mimetype-messages",{prefix:"attachment.validation.mimetype.",keys:["errorMessage","allowedMimetypes","blockerMimetypes"]});
require(["jquery","xwiki-l10n!attachment-validation-mimetype-messages","xwiki-events-bridge"],(e,f)=>{function k(g,b){return g.some(a=>{const c=a.indexOf("*");if(-1===c)return a===b;const d=a.substring(0,c);a=a.substring(c+1,a.length);return b.startsWith(d)&&b.endsWith(a)})}const h={};e(document).on("xwiki:actions:beforeUpload",function(g,b){if(b.documentReference){h[b.documentReference]||e.ajax({url:(new XWiki.Document(XWiki.Model.resolve("XWiki.Attachment.Validation.Code.MimetypeValidation",XWiki.EntityType.DOCUMENT))).getURL("get",
e.param({outputSyntax:"plain",documentReference:b.documentReference})),async:!1,method:"GET",success:function(n){h[b.documentReference]=n}});var a=h[b.documentReference]}else a=document.getElementById("attachment-validation-mimetypes-configuration").textContent;var c=JSON.parse(a),d=b.file.type.toLowerCase();a=c.allowedMimetypes;c=c.blockerMimetypes;const l=0<a.length,m=0<c.length;if(l&&!k(a,d)||m&&k(c,d))d=f.get("errorMessage",b.file.name,d),l&&(d+="\x3cbr/\x3e"+f.get("allowedMimetypes",a)),m&&(d+=
"\x3cbr/\x3e"+f.get("blockerMimetypes",c)),new XWiki.widgets.Notification(d,"error"),g.preventDefault()})});

I also discovered that (next to the image UI upload) I can copy / paste files into the WYSIWYG editor sucesfully. (both the WYSIWYG editor and the image uploading works normally).

If the above is confirmation of the XWiki.Attachment.Validation.Code.MimetypeValidation or XWiki.Attachment.Validation.Code.FileSizeValidation UIXs not being correctly loaded, how does one go about loading these UIXs?

If they are not loaded, we’ll need to find out why :slight_smile:

Sorry, my request wasn’t really clear. I mean in the html of the page. See the screenshot below.
What I want to check is the presence of the elements with the two ids and their content.

image

I can see both in the index of the example page !
index.txt (92.7 KB)

image

Thanks @Wardenburg,

That’s a good start but I’ll need to ask for more :slight_smile:

I need to see the content of the elements with id="attachment-validation-filesize-configuration" and id="attachment-validation-mimetypes-configuration" in the html as well.

1 Like

Ah, apologies @mleduc , I attached these two files to this post.

image

MimetypeValidation.txt (1.3 KB)
FileSizeValidation.txt (1.1 KB)

Thank you v. much for your assistance!

Thanks. I’m very sorry but it’s not yet what I asked for :slight_smile:

Let’s try another way. Can you visit a page where you encounter the issue, then show the source of the page (right click → View page source) and share with me the whole source of the page?

Another question, can you take a screenshot of the history of XWiki.Attachment.Validation.Code.FileSizeValidation and XWiki.Attachment.Validation.Code.MimetypeValidation?

1 Like

Apologies for not supplying you with the right info mleduc, I like to think I’m learning however, for instance that these validation scripts are pages on the wiki

The index.txt from this post was my attempt at this, I’ll use view page source in the future!

Here is a view page source export. note that this is with the attachment tab open after a (failed) attempt to upload using the button in the attachment tab.

view-source_https___xwikiurl.nl_Main_Werkwijze_Portalen_#Attachments.txt (406.9 KB)
Nb. .html file with a .txt extension.

image

I noted that when I click on ‘version’ in the top bar of the version history I get an error (the user I’m logged into as is the original admin account from installation - is this perhaps because I did the update from webmin?).

It might just aswell be that these scripts are intended to be called upon and not viewed from the page itself…

image

and the same for MimetypeValidation

image

image

Thank you for your continued assistance @mleduc !

ok, apparently the last author author of XWiki.Attachment.Validation.Code.FileSizeValidation and XWiki.Attachment.Validation.Code.MimetypeValidation does not have the script right of those documents.

A quick fix for now is either to give script rights of this user (Jesse Veentjer) if you trust that account.
Another option is to do a small edit (e.g., a newline at the end of the content) on those pages with another user with script rights.

I’ll also check if this is a consequence of a bug and design issue on our end.

1 Like

Oh I feel like we’re getting warmer.

I attempted to add a newline to the velocity on the page. on the mimetypevalidation the error is no longer visible.

On the filesize validation however the error remains. Also the issue is not yet resolved.
image

I also note the top version remains the ’ coming from extension Attachment Validation Application 14.10.3’ which links to the page with the error (and I cant seem to change that page)

Perhaps it just needs a restart; I will restart the environment and update you below with my findings.

Unfortunately also after a complete restart the issue remained (after a newline was added to the velocity script on both the mimetypevalidation and the filesize validation page).

Are you sure the user you did the documents edit with has script rights?

Hey @mleduc , I double checked and indeed it does.

It’s superadmin, part of the xwiki admin group, I also assigned full personal rights to the user both on the page & children of the wiki as on the 'demo’page which Ive been using to attempt uploading a file.

image

To triple check I added all rights rights for both the user and the admingroup to the FileSizeValidation , MimetypeValidation and the demopage. added a newline to the velocity scripts and restarted the xwiki.


image

image

Unfortunately the error remains

image

I did notice that both the attachment and the validation parent pages of the codes are not ‘openable / found’ when I click on them, is that as intended?

image

I also noticed on FileSizeValidation that while the MimeTypeValidation velocity script shows an empty page. The FileSizeValidation script prints {“maxFileSize”:“107374182400”} on the page (I think I set this value through both the config file as the xwiki management interface), is that intended?

image

My thinking is that perhaps the parameter portion of the FileSizeValidation error refers to where its getting the {“maxFileSize”:“107374182400”} from (I’m usure however what part of the velocity code makes the{“maxFileSize”:“107374182400”} show on the page however)

@Wardenburg I have another idea. Is you skin customized?

I noticed from the html of a page you provided, that a while div element with id headerglobal is missing.
This div is the one containing the elements whose absence is making the attachment upload javascript fail.

The file defining this block is named global.vm.
By default this file is included from header.vm

1 Like

I added my own css to wiki/StyleSheetExtension
image

and have a topbar set up through the menu structure admin panel, but this is disabled / not showing
image

otherwise no adjustments.

Another issue I’m having which I thought was unrelated; since the upgrade Im having to remove cookies a lot more often for my admin account; if I don’t the entire wiki shows as ‘not reachable’ unless I remove cookies and restart edge (or use private mode). After the removal and restart the page loads normally.

image

Strangely enough other devices don’t seem to have this issue at all and I’ve ruled out a dns issue, sidenote here that as of yet there arent many other users on the wiki.

I disabled addblocker to see if the issue maybe comes from that direction, thank you for your ideas and assistance and I’ll keep you posted if anything changes.

short update, I don’t know if it’s turning off of the addblocker or something else but I could now change the FileSizeValidation file (with the ‘empty newline’) so that it no longer gives the rightserror.

Upon further inspection it seems that the cookie deletion must be a local issue; when I close edge and open it again the page loads normally - and others dont have the same issue. (nb. I double checked cookies dont auto delete upon closing the browser)

Unfortunately despite these developments the issue remains!

updated to 15.0 , no effect on the issue :frowning:

I’ve done some more searching and it seems my initial answer on the ‘skin customisation’ was incorrect (I’m also not sure if you didnt mean custom skins like ‘flamingo’, which we use), and while I’m learning a lot about xwiki I feel bad for supplying you with wonky information (despite my best attempts) - apologies!

Anyhoo: I forgot about all of this but initially while searching for a way to get a top bar on the wiki I did add an xwiki.xwikiskin obbject to the flamingo baseskin

image

It was entirely empty except a commented out html in the ‘header’ section … … but when I removed the customisation… the error dissapeared! it works now!

The whole thing seems odd to me and I have no way the implications this might have but I’m very happy the issue is gone!

Thank you v. much @mleduc , couldnt have done it without you

1 Like