sp-dev-docs icon indicating copy to clipboard operation
sp-dev-docs copied to clipboard

SPFx Extension app package periodically fails to load JavaScript files

Open sionjlewis opened this issue 7 years ago • 56 comments

Category

  • [] Question
  • [x] Bug
  • [] Enhancement

Expected or Desired Behavior

SPFx Extension to load when page is requested. Steps:

  • Upload SPFx Extension to the App Catalog and select Tenant wide deployment
  • Run the Add-PnPCustomAction PowerShell CommandLet (for a specific site)
  • Load a modern site page ALL OK

Observed Behavior

The SPFx Extension will load OK for weeks and then "out of the blue" if fails with errors like:

GET https://[tenent].sharepoint.com/sites/apps/ClientSideAssets/[guid]/extention-name-application-customizer_[guid].js net: ERR_ABORTED 404 HEAD https://[tenent].sharepoint.com/sites/apps/ClientSideAssets/[guid]/extention-name-sp-page-assembly_[guid].js 404

Steps to Reproduce

Not sure how we can reproduce this problem?

  • The problem:
    • Occur generally on or just after a Tuesday (New Zealand time)
    • Occurs for multiple tenants, but generally not all at the same time
    • Affect all SPFx Extensions (when it happens)
    • Does not affect SPFx Webparts
  • The JavaScript files appears to be from an older versions of the App Package (we have started a log to confirm this assumption)
  • When an error occurs, the SPFx Extension does not load
  • Opening the Browser Console locate the error:
    • Copy and past the JavaScript's URL into a browser window will also show a 404 error
    • Remove the File name & extension from the URL will open the container folder (no errors)
  • This may not be an SPFx Extension bug but rather an Office 365 update issue?

Possible solution:

I assume the GUIDs used within the file names as for cache-busting purposes. Why not remove the GUID from file name and apply it to the requesting code as a query string parameter?

Ideas and suggestions are welcome :)

#sp-dev-fx-extensions

sionjlewis avatar Apr 17 '19 04:04 sionjlewis

Thank you for reporting this issue. We will be triaging your incoming issue as soon as possible.

msft-github-bot avatar Apr 17 '19 05:04 msft-github-bot

Can confirm have seen this multiple times.

nateforsyth avatar Apr 17 '19 06:04 nateforsyth

If you browse the directory when you get a 404, can you find the file? If you can, can you select it from the library? If so, does it load, and if so, does the URL match the original request URL?

Also - can you look at the response headers and response body of the original 404? Does anything look out of whack?

patmill avatar Apr 17 '19 17:04 patmill

If you browse the directory when you get a 404, can you find the file? Yes there are files, however their names end with different GUIDs ~/ClientSideAssets/[EXT-GUID]/extension-name-application-customizer_[FILE-GUID].js

If you can, can you select it from the library? Yes, the files within the library load without errors (OK)

If so, does it load, and if so, does the URL match the original request URL? A. Yes the file Loads. B. No, the files has a different GUID appended to the file name ~/ClientSideAssets/[EXT-GUID]/extension-name-application-customizer_[FILE-GUID].js

Also - can you look at the response headers and response body of the original 404? I will have to wait for the next incident and get back to you.

Does anything look out of whack? TBC: assuming not as the request is for a different file name.

sionjlewis avatar Apr 17 '19 20:04 sionjlewis

That's super weird. Are you updating your solution in any way? Are you uploading code separate from the solution?

The path should be in the solution manifest, so it's really strange that it should not match. Let's try this: 1 - Go to the component manifests list in your app catalog. It can be reached at yourtenant.sharepoint.com/sites/yourappcatalog/Lists/ComponentManifests/AllItems.aspx 2 - Find the manifest of the component that is misbehaving 3 - Look at the references in that file. Do they match with the file names that are in the code assets library? 4 - if not, can you see what the last modified time is on the original solution, the entry in the manifest list, and the entry in the assets library?

Those should all be in sync for the most part, and (unless there is some strange caching at play) the only reason the code filename should change is because the solution was updated, it had a manifest change, and a new bit of code.

patmill avatar Apr 17 '19 21:04 patmill

Following on from what @sionjlewis has said above, it's worth noting a few other things; every time this occurs:

  • there has been an update to our extensions project 1-2 days before.
  • the updates are done within the SPFx project.
  • the project is built and bundled using the documented gulp based processes.
  • the package-solution.json version is incremented.

These next points may be a red herring, however the timing seems consistent.

  • this always seems to occur between the Tuesday - Wednesday window.
  • this feels like the server is performing a post-update rollback to a predefined state.
  • the filename it's attempting to load appears to be old (unconfirmed).
  • the filename being loaded is different to what is within the ClientSideAssets folder for the extension (as previously mentioned).

Hope this helps.

nateforsyth avatar Apr 17 '19 21:04 nateforsyth

Are you updating your solution in any way? From our recollection, this only seems to happen on environments where the package has been updated.

Are you uploading code separate from the solution? No, all the code is deployed using an App Package

The path should be in the solution manifest, so it's really strange that it should not match. Agree; it's like the "system" has be partially rolled back (back-up & restore)...

Let's try this:

1 - Go to the component manifests list in your app catalog. It can be reached at yourtenant.sharepoint.com/sites/yourappcatalog/Lists/ComponentManifests/AllItems.aspx 2 - Find the manifest of the component that is misbehaving 3 - Look at the references in that file. Do they match with the file names that are in the code assets library? 4 - if not, can you see what the last modified time is on the original solution, the entry in the manifest list, and the entry in the assets library?

Thanks for the URL. Unfortunately I'm unable to reproduce the error right now, as we had to apply the a fix ASAP. If/when the error occurs in our Test environment then we will be able to follow your steps above and get back to you.

Currently our fix is to replace the existing package (i.e. re-upload it). It does not require a rebuild (or changing package version).

Those should all be in sync for the most part, and (unless there is some strange caching at play) the only reason the code filename should change is because the solution was updated, it had a manifest change, and a new bit of code.

Make sense and logically agree :)

I don't want to muddy the water; however, I have wondered if this issue is related to the SharePoint Online Update process?

Remembering back to SharePoint 2007 & 2010 On-Premises days, we use to back up a site collection's database and file system separately. If these back-ups were slightly out of sync then we would see similar issues on a restore...

In the meantime here's a screen shot: MegaMenu-JS-Loading-Bug

sionjlewis avatar Apr 17 '19 21:04 sionjlewis

I don't think SPO updates are the cause here. The GUID in that file name is generated during the build process of the solution, and a reference is added to the manifest during gulp bundle and gulp package-solution --ship . Any change to the path would come from an upload to the library, either because of an update to the solution (which cracks the solution file and copies the files) or because someone updated the files directly. My only guess is that there is a cache issue, where the solution is updated, the manifest is changed, the new files are uploaded, but the manifest is cached somewhere and an old reference is getting used.

patmill avatar Apr 17 '19 22:04 patmill

The GUID in that file name is generated during the build process of the solution, and a reference is added to the manifest during gulp bundle and gulp package-solution --ship .

Yes, 100% agree that is what the SPFx build process does.

Any change to the path would come from an upload to the library, either because of an update to the solution (which cracks the solution file and copies the files) or because someone updated the files directly.

Yes, also agree. NOTE: we are not uploading the files directly :)

My only guess is that there is a cache issue, where the solution is updated, the manifest is changed, the new files are uploaded, but the manifest is cached somewhere and an old reference is getting used.

A "Cache issue" would seem a plausible explanation. However the error does not occur immediately after and update. If it did then replicating the error would be much easier...

  • We have previously tried deleting the App Package and JavaScript folder (located in ClientSideAssets) before re-uploading the Package to the App Catalog. This has fixed the immediate problem, but in some cases the issue has reoccurred some time later (days or weeks).

  • What we haven't checked is that the "~/Lists/ComponentManifests" items have been deletes too.

If it's a "Cache issue", any ideas on how can we fix it?

sionjlewis avatar Apr 18 '19 01:04 sionjlewis

I've had issues with extensions before the latest SPO updates and the following steps helped (may not be the case with OP's issue).

  1. As mentioned, always increment the version number of your solution before deployment.
  2. Don't let SharePoint update the extension for you. Use Uninstall-PnPApp to remove the old version and then use Install-PnPApp to install the new version. I found that doing these steps through the GUI would cause issues as sometimes, the uninstall stage would still be in progress even though the GUI would indicate otherwise. The PnP Install would fail if other operations are still in progress (might be worth just waiting 30 mins after an uninstall just to be safe).
  3. Whenever you install an extension "App" you also get a CustomAction added to your SPWeb. Keep track of those and make sure that when you update an extension, 1 CustomAction is deleted after uninstall and that an install adds 1 CustomAction. You can keep an eye on those with Get-PnPCustomAction

semopz avatar Apr 23 '19 11:04 semopz

Hi @semopz, Great to hear your experience with this issue.

  1. As mentioned, always increment the version number of your solution before deployment.

Yes / thumbs-up

  1. Don't let SharePoint update the extension for you. Use Uninstall-PnPApp to remove the old version and then use Install-PnPApp to install the new version. I found that doing these steps through the GUI would cause issues as sometimes, the uninstall stage would still be in progress even though the GUI would indicate otherwise. The PnP Install would fail if other operations are still in progress (might be worth just waiting 30 mins after an uninstall just to be safe).

Interesting; we have previously had issues with the Install-PnPApp cmdlet timing out, so started using a manual process (the UI) instead. Will try PowerShell next time, to see if that resolves the issue.

I have a concern regarding "... waiting 30 mins after an uninstall ...", as this often not possible on 'live' systems. So some more thought will be required...

  1. Whenever you install an extension "App" you also get a CustomAction added to your SPWeb. Keep track of those and make sure that when you update an extension, 1 CustomAction is deleted after uninstall and that an install adds 1 CustomAction. You can keep an eye on those with Get-PnPCustomAction

Excellent point, we will include that in our monitoring of the issue/bug

Thank you

Updated to checklist:

  • https://[tenent].sharepoint.com/sites/[app-catalog]/Lists/ComponentManifests/
  • https://[tenent].sharepoint.com/sites/[app-catalog]/ClientSideAssets/[SPFx-Ext-GUID]/
  • Get-PnPCustomAction

sionjlewis avatar Apr 23 '19 22:04 sionjlewis

@sionjlewis - Seems based on your last reply this issue can be closed as resolved... correct?

andrewconnell avatar Apr 24 '19 14:04 andrewconnell

Hi @andrewconnell, I think you may have misunderstood my last comment, the issue/bug is not resolved.

I suspect the issue/bug lies with the underlying SharePoint infrastructure and not necessarily with the SPFx framework. @semopz may back this assumption up in his/her post, point 2 and 3. However we are still trying to gather evidence so that others may replicate.

At the end of my last post I created a checklist, of things we will log next time a SPFx Extension fails to load.

Notes:

  • We have not had any issues with SPFx Webparts loading
  • SPFx Extensions loads OK when deployed
  • SPFx Extensions have a pattern of failing on Tuesdays intermittently

sionjlewis avatar Apr 25 '19 01:04 sionjlewis

Hi all and @sionjlewis

I apologise for the length of this reply in advance. I was able to capture this issue occurring on 3 tenants yesterday. I've managed to get screenshots as well as an extract of the Client Side Component Manifest list items when it occurred on all of them, though I'll only show you the results from one of them.

A successful update

It started last Friday, had to update our extension package on a client environment.

1a Extension state - Apps - the update from last week

Here's the Apps for SharePoint interface at the point of updating the extension package on 17th May 2019, note the version number.

1 - extension state - Apps - (the update) - 20190517

1b Extension state - Client Side Assets - the update from last week

Here's the Client Side Assets folder on the same day, 17th May 2019.

extension state - Client Side Assets - 20190517

1c Extension state - Client Side Component Manifests - the update from last week

And here's the Client Side Component Manifests List on 17th May 2019.

3 - extension state - Client Side Component Manifests - (the update) 20190517

At this point everything was going well. Although the screenshot doesn't show it, the 5x entries for each Extension were pointing to the same .js file within the ClientSideAssets folder.

Github, we have a problem

Yesterday (Monday) it was noticed that the Manifests didn't look the way they did on Friday.

2a Extension state - Client Side Assets - the failure

Here's the Client Side Assets folder, 20th May 2019 (note the date).

2b - extension state - Client Side Assets - (the update) - 20190520

2b Extension state - Client Side Component Manifests - the failure

Here's the Client Side Component Manifests list beside the console logging when the failure occurred.

Note where:

  • the first manifest .js file has a different random string applied, this references the correct version of the file (confirmed).
  • the 2nd through 5th entries now reference the previous .js files

4 - extension state - Client Side Component Manifests - (the failure) - 20190520

This is what was replaced on 17th May 2019

Note the date and random string matches the 4 items that have reverted in the previous screenshot.

Mega Menu state 20190417

The fix

Fixing this appears to be permanent, until the next time we update our extension project/s.

I remove the client side assets for the package, as well as the app itself, before clearing out the recycle bin.

3a Extension state - Apps for SharePoint - new package

Here's where I have uploaded a freshly packaged .sppkg file to the Apps for SharePoint interface.

2a - extension state - Client Side Assets - (the update) - 20190517

3b Extension state - Client Side Assets - new package

This is the state of the Client Side Assets folder after uploading the new package.

5a - extension state - Client Side Assets - (post-fix) - 20190520

5b Extension state - Client Side Component Manifests - new package

And this is the way I expect to see the Client Side Component Manifests List when a new package is uploaded.

This is the state it's currently in.

5b - extension state - Client Side Component Manifests - (post-fix) - 20190520

6 Extension state - Client Side Component Manifests - an extract

And finally, here's an extract of the manifests from the list that has all of the differing .js filenames.

extension state - Client Side Component Manifests - 20190520.txt

Notes and caveats

  • this occurs when a new version of an Extension package is uploaded.
    • when this happens, it's always a Monday or Tuesday.
    • this may still be circumstantial, but 3 tenants did this between 3pm and 5pm yesterday (local time)).
    • only one of the 3 tenants were updated last week; the other two were updated around 1pm yesterday.
  • repairing this necessitates the following steps:
    • fresh build of the .sppkg file.
    • removal of the applicable Client Side Assets folder.
    • deletion of the existing .sppkg file from the Apps for SharePoint interface.
    • clear out the first stage recycle bin on the App Catalog site.
    • clear out the second stage recycle bin on the App Catalog site.
    • upload the new .sppkg, set to tenant wide deployment (automatically publishes).

The repair steps are a work-around at best due to this behaviour being seemingly random.

Thanks for reading, looking forward to some sort of action or guidance on this issue.

nateforsyth avatar May 21 '19 02:05 nateforsyth

In follow up. I left another tenant with an update yesterday to see whether it'd fail today. It has. I've just replicated the issue again. Note here that 4/5 of the entries are referencing the old .js file again (all 5 were the same yesterday).

extension state - Client Side Component Manifests - 20190521

nateforsyth avatar May 21 '19 05:05 nateforsyth

Thanks @nateforsyth, We had been waiting sometime to be able to reproduce the problem, let's hope this enough to find a solution...?

sionjlewis avatar May 27 '19 04:05 sionjlewis

I can add that this has nothing to do with the storage location of the Javascript files. We are also sometings seeing old files being loaded but we upload the assets to our own CDN. As we so far never deleted anything from our CDN we don't get 404s, but instead we get the old versions of the files. Sometimes they are several days old. It's not a browser cache issue either because this also happens after clearing the browser cache.

cwdata avatar May 29 '19 10:05 cwdata

Thanks @cwdata, Even though you don't get 404 errors, responding with the wrong files is still an error...

sionjlewis avatar May 29 '19 20:05 sionjlewis

Thanks @cwdata that's definitely helpful.

Have you looked at your Client Side Component Manifests List when this occurs? Would be interested to see whether or not you're seeing the discrepancies within the List items for the manifest like we were.

https://[tenaneName].sharepoint.com/sites/[appCatalogName]/Lists/ComponentManifests/

Using the App Catalogue, updates to our packages overwrite the Client Side Assets folder, meaning that the old .js files are removed. Upon this failure they obviously cannot be resolved anymore.

Yours sounds like the exact same issue to me, where you have the old versions it makes perfect sense that you're seeing old versions of your components render unexpectedly.

I'd bet money on a 404 like we get if you were to temporarily remove the old versions.

This has been tried on another tenant that failed today and doesn't work:

~We've also realised that the Client Side Component Manifests List items are editable. We're going to try editing the manifests directly to resolve the ambiguity next time it happens - a hot fix if you will (we're not sure if it'll resolve the issue). We consider this a hacky work-around though and definitely something that should be fixed.~

Thanks again for confirming :)

nateforsyth avatar May 29 '19 20:05 nateforsyth

Ignore the above reference, I posted a reply to an incorrect thread.

nateforsyth avatar Jun 11 '19 22:06 nateforsyth