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

fix: getUploader should only be called when a new UploadPicker instance is created #887

Merged
merged 1 commit into from
Jul 10, 2023

Conversation

susnux
Copy link
Contributor

@susnux susnux commented Jul 8, 2023

Finally solved the issue with the @nextcloud/cypress update:

image

@susnux susnux added the 3. to review Waiting for reviews label Jul 8, 2023
@susnux susnux requested a review from skjnldsv July 8, 2023 22:37
@susnux susnux added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Jul 8, 2023
Copy link
Contributor

@skjnldsv skjnldsv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum, I actually don't get why that would change anything ?
The uploader init is irrelevant to the Vue component. It doesn't matter if it's created before or while the vue component is initiated?

@skjnldsv skjnldsv dismissed their stale review July 9, 2023 09:21

Commented

@susnux
Copy link
Contributor Author

susnux commented Jul 9, 2023

@skjnldsv because before this the bundled file looks like this:

const uploadManager = getUploader();
var UploadPicker = // ...
// ... more stuff ...
let _uploader = null
function getUploader() {
   /// ...
}

So as uploadManager is on the global scope, it will get initialized first by calling uploadManager() but _uploader was not declared at this time, as the interpreter is still on the uploadManager line.

With this changes it looks like this

var UploadPicker  = {
    // ...
    data() {
        uploadManager: getUploader(),
        // ...
    }
}
// ... more stuff ...
let _uploader = null
function getUploader() {
   /// ...
}

so this time everything is declared first before it is used.

To see the error in action you can try this exampel in Node or your browser console:

const uploadManager = getUploader()
let _uploader = null
function getUploader() {
   if (_uploader === null) return _uploader = 'uploader'
   return _uploader
}

The node error message is not that helpful I think:

ReferenceError: Cannot access '_uploader' before initialization

But on Firefox it makes sense:

Uncaught ReferenceError: can't access lexical declaration '_uploader' before initialization

…stance is created

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
@susnux susnux requested a review from skjnldsv July 9, 2023 15:12
@susnux susnux added bug Something isn't working 3. to review Waiting for reviews and removed 2. developing Work in progress labels Jul 9, 2023
@susnux
Copy link
Contributor Author

susnux commented Jul 9, 2023

Found the reason for the cypress issue here and fixed that :)

@codecov
Copy link

codecov bot commented Jul 9, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (c466817) 33.50% compared to head (d00589a) 33.50%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #887   +/-   ##
=======================================
  Coverage   33.50%   33.50%           
=======================================
  Files           6        6           
  Lines         200      200           
  Branches       31       31           
=======================================
  Hits           67       67           
  Misses        131      131           
  Partials        2        2           

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@skjnldsv
Copy link
Contributor

Wow, this is very interesting!
The import order does make a difference in bundling, TIL

@skjnldsv skjnldsv merged commit a853b2d into master Jul 10, 2023
15 checks passed
@skjnldsv skjnldsv deleted the fix/use-before-init branch July 10, 2023 09:07
@skjnldsv skjnldsv added 4. to release Ready to be released and/or waiting for tests to finish and removed 3. to review Waiting for reviews labels Jul 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4. to release Ready to be released and/or waiting for tests to finish bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants