-
Notifications
You must be signed in to change notification settings - Fork 3
Do not use optional chaining on a potentially undeclared root object #383
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
Do not use optional chaining on a potentially undeclared root object #383
Conversation
The global "OC" variable may be undefined depending on the
initialization order, so optional chaining ("OC?.config" and
"OC?.debug") was added to prevent accessing fields on an undefined
variable.
However, "OC" could be not only undefined, but also undeclared. Optional
chaining can not be used on an undeclared root object, so it needs to be
explicitly guarded against that to prevent a ReferenceError to be
thrown.
Signed-off-by: Daniel Calviño Sánchez <[email protected]>
ChristophWurst
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
window.OC?.config?.loglevel might work as well, assuming window is always declared?
|
While this will fix the issue, but it will make the feature useless. |
Good point, I tried that and it seems to work as expected. However, I have never used TypeScript, so I do not know if something needs to be changed above in
But this is essentially the same thing fixed by #362. Why is guarding against undeclared a problem but guarding against undefined fine?
I totally agree, that would be the best solution. Unfortunately I do not know how to do that :-) |
Yes it is, but I thought it was about CI builds where the The logging level is only configured once, so sometimes the app will log as configured and sometimes falling back to the default even when something more verbose was configured. |
Ah, ok :-)
Without the fix they will fail to load at all in a nondeterministic way, which is even worse :-P So I would apply the current fix for the time being until the proper fix can be developed. Of course if the proper fix can be ready soon (I mean, before the Nextcloud 25 RCs) then better go for the proper fix instead, but I do not know how to do it. |
Currently I can only think of something like this as a solution: Not sure if this is the right way to go |
I have tested it (also replacing |
PVince81
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Follow up to #362
The global
OCvariable may be undefined depending on the initialization order, so optional chaining (OC?.configandOC?.debug) was added to prevent accessing fields on an undefined variable.However,
OCcould be not only undefined, but also undeclared. Optional chaining can not be used on an undeclared root object, so it needs to be explicitly guarded against that to prevent aReferenceErrorto be thrown.The
ReferenceErrorcan be seen in the PDF viewer since the update of nextcloud/logger to 2.2.1 (note that it also happened after the update to 2.2.0).