OrchardCMS / OrchardCore

Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
https://orchardcore.net
BSD 3-Clause "New" or "Revised" License
7.37k stars 2.38k forks source link

Media Library not being initialized correctly when browser history is totally cleaned or Orchard Core is run for the first time in a browser. #6884

Closed OrchardSkills closed 4 years ago

OrchardSkills commented 4 years ago

Media Library not being initialized correctly when browser history is totally cleaned or Orchard Core is run for the first time in a browser. An example is selecting the blog theme. Edit the blog post. Delete the image. Try to load the image back. No images are found. There should be a list of images loaded through the recipe. Add a new image. The image shows up. Select it. Delete it again. Publish the blog post. Go back to edit it again. Try again to add an image. No images are found. Workaround: Create a directory. Now all the images show up on the list. Media-Library-Bug

deanmarcussen commented 4 years ago

Yes, this issue has been seen before (we even saw it during a demo once, and then neither Seb nor I could repro it the next day)

Here's what I know

here's what fixes it

If you are currently able to repro it @OrchardSkills what would be useful is to confirm the two js calls mentioned above in the chrome dev tools (screen shots be helpful), with both their return values, and the order in which they are returned.

What I personally think is there is an event being called in the vue app with either bad data, or out of the correct order, which can occur sometimes on fresh installs.

If you wanted to try and debug it down @OrchardSkills I would start in the js app.

btw, just tried now, can't repro again, but I've seen it, so I know it's a real thing.

OrchardSkills commented 4 years ago

I can reproduce it every time with the Blog recipe.

Check out this video on Orchard Skills: https://youtu.be/7F00sYlhtno

Yes, Dean. I can debug through it and see whats going on.

This only occurs when the complete browser history is cleared or running Orchard Core in a browser the first time.

There is an issue with the media library. media.js self.loadFolder(folder) is never called until add or move a folder event occurs. On a browser, that hasn't run Orchard Core or the history and cache have been cleared, The function self.loadFolder(folder) should be called at the initialization.

May aso want to call self.loadFolder(folder) during the folderSelected event:

      bus.$on('folderSelected', function (folder) {
        self.loadFolder(folder);
        self.selectedFolder = folder;
      });

That way if a folder is selected it will load and display the list.

jtkech commented 4 years ago

Okay i can repro under a new browser or under Chrome if i remove the mediaApplicationPrefs item from the local storage.

You don't need to add loadFolder() as it is done when you update the selectedFolder property that is watched, but it needs to be set with a new object. I will do a PR to fix it when i will have time as i need to run the gulp pipeline.

deanmarcussen commented 4 years ago

awesome @OrchardSkills you found the repro for it!

That's been occasionally bugging me for a year and a half now :)

jtkech commented 4 years ago

I fixed it this night, in app.js we need to add line 120

                if (!localStorage.getItem('mediaApplicationPrefs')) {
                    self.selectedFolder = _root
                    return;
                }

                self.currentPrefs = JSON.parse(localStorage.getItem('mediaApplicationPrefs'));

But i had problem with npm install, i spent a part of the night to understand why it was executing in an infinite loop the install scripts of the root package.json, i needed to replace cd src/OrchardCore.Themes/TheAgencyTheme with cd src/OrchardCore.Themes/TheAgencyTheme/wwwroot to make it working. This because in TheAgencyTheme there is a root package.lock.json but no package.json, only under wwwroot.

@agriffard do we need both? OR which one?

But then gulp build was failing, otherwise for testing by changing the script directly under wwwroot, it was working

So i think that currently with the last dev there is a problem with npm install and gulp cmds

I'm going to sleep, will see tomorrow ;)

agriffard commented 4 years ago

I added package.json into TheAgencyTheme.

OrchardSkills commented 4 years ago

@jtkech Thanks for the fix!