Skip to content

bug(service-worker): / path is omitted by ngsw-config #19945

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

Closed
lacolaco opened this issue Oct 26, 2017 · 13 comments
Closed

bug(service-worker): / path is omitted by ngsw-config #19945

lacolaco opened this issue Oct 26, 2017 · 13 comments
Labels
area: service-worker Issues related to the @angular/service-worker package

Comments

@lacolaco
Copy link
Contributor

lacolaco commented Oct 26, 2017

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

Currently, an index path, /, is omitted by ngsw-config command. It was supported as routing in old ngsw version.

$ ngsw-config ./src ./src/ngsw.base.json

ngsw.base.json

{
  "index": "src/index.html",
  "assetGroups": [
    {
      "name": "site",
      "mode": "prefetch",
      "resources": {
        "files": [
          "/",
          "/favicon.ico",
          "/index.html"
        ],
        "urls": [
          "https://fonts.googleapis.com/**"
        ],
        "versionedFiles": [
          "/*.bundle.css",
          "/*.bundle.js",
          "/*.chunk.js"
        ]
      }
    }
  ]
}

Generated ngsw.json

{
  "configVersion": 1,
  "index": "/src/index.html",
  "assetGroups": [
    {
      "name": "site",
      "installMode": "prefetch",
      "updateMode": "prefetch",
      "urls": [
        "/favicon.ico",
        "/index.html"
      ],
      "patterns": [
        "https:\\/\\/fonts\\.googleapis\\.com\\/.*"
      ]
    }
  ],
  "dataGroups": [],
  "hashTable": {
    "/favicon.ico": "84161b857f5c547e3699ddfbffc6d8d737542e01",
    "/index.html": "e5defb09b5dadd8903d71b868022bf69fc954f39"
  }
}

Expected behavior

/ should be emitted as urls to cache index.html for offline support.

{
  "configVersion": 1,
  "index": "/src/index.html",
  "assetGroups": [
    {
      "name": "site",
      "installMode": "prefetch",
      "updateMode": "prefetch",
      "urls": [
        "/", // <= should be in here
        "/favicon.ico",
        "/index.html"
      ],
      "patterns": [
        "https:\\/\\/fonts\\.googleapis\\.com\\/.*"
      ]
    }
  ],
  "dataGroups": [],
  "hashTable": {
    "/favicon.ico": "84161b857f5c547e3699ddfbffc6d8d737542e01",
    "/index.html": "e5defb09b5dadd8903d71b868022bf69fc954f39"
  }
}

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

I tried to migrate my app to new ngsw with #19795 as a referrence. But index.html is never cached.

Environment

Angular CLI: 1.5.0-rc.3
Node: 6.11.2
OS: darwin x64
Angular: 5.0.0-rc.6
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router, service-worker

cc/ @alxhub @webmaxru

@webmaxru
Copy link
Member

You don't need to add / at all. The routing is done automatically now (there is no need to specify anything for this anymore). I believe you have caching failed because of non-default base-href. Do you pass it as a 3rd parameter to ngsw CLI? In your case it should look like this: ngsw-config dist src/ngsw.base.json /src

Offtop: @lacolaco, I'm in Tokyo Nov 13-16. My pleasure to meet you and maybe present something at ngJapan meetup!

@lacolaco
Copy link
Contributor Author

lacolaco commented Oct 26, 2017

Hmm... I changed index property from /src/index.html to /index.html, but it seems not working well.

generated ngsw.json

{
  "configVersion": 1,
  "index": "/index.html",
  "assetGroups": [
    {
      "name": "site",
      "installMode": "prefetch",
      "updateMode": "prefetch",
      "urls": [
        "/favicon.ico",
        "/index.html"
      ],
      "patterns": [
        "https:\\/\\/fonts\\.googleapis\\.com\\/.*"
      ]
    }
  ],
  "dataGroups": [],
  "hashTable": {
    "/favicon.ico": "84161b857f5c547e3699ddfbffc6d8d737542e01",
    "/index.html": "e5defb09b5dadd8903d71b868022bf69fc954f39"
  }
}

image

this project is made by Angular CLI and I added ngsw files.

image

P.S. @webmaxru I want to see you, too! please send email to suguru.inatomi[at]gmail.com about your trip. Let's adjust our schedule :)

@webmaxru
Copy link
Member

Try to upgrade to RC.6. Most likely it's the same bug as was in #19490

@matsko matsko added the area: service-worker Issues related to the @angular/service-worker package label Oct 26, 2017
@lacolaco
Copy link
Contributor Author

I already upgraded to RC.6. (see environments in 1st comment)

@lacolaco
Copy link
Contributor Author

still happening in RC.7

@alxhub
Copy link
Member

alxhub commented Oct 27, 2017

Hi @lacolaco,

Once your site loads, please open a tab and access the debugging URL /ngsw/state, and paste the contents here.

Thanks!

@lacolaco
Copy link
Contributor Author

@alxhub Thank you. the below is that.

NGSW Debug Info:

Driver state: NORMAL ((nominal))
Latest manifest hash: none
Last update check: never



=== Idle Task Queue ===
Last update tick: never
Last update run: never
Task queue:


Debug log:

@alxhub
Copy link
Member

alxhub commented Oct 28, 2017

@lacolaco please have that URL open, refresh your app, wait a few seconds and refresh the debug URL. That log indicates a service worker that has never seen a fetch.

@lacolaco
Copy link
Contributor Author

@alxhub that's right. there is no log.

2017-10-28 10 13 26

The weird thing is favicon.ico is cached correctly. Why not index.html?

@lacolaco
Copy link
Contributor Author

lacolaco commented Oct 28, 2017

Ahhh, sorry, I had been enabled service worker's update on reload option. I just got actual logs

NGSW Debug Info:

Driver state: EXISTING_CLIENTS_ONLY (Degraded due to failed initialization: Hash mismatch (cacheBustedFetchFromNetwork): http://localhost:4200/index.html: expected e5defb09b5dadd8903d71b868022bf69fc954f39, got 002a296589766e144eda3002b7feb8b6e5ee1ac5 (after cache busting)
Error: Hash mismatch (cacheBustedFetchFromNetwork): http://localhost:4200/index.html: expected e5defb09b5dadd8903d71b868022bf69fc954f39, got 002a296589766e144eda3002b7feb8b6e5ee1ac5 (after cache busting)
    at PrefetchAssetGroup.cacheBustedFetchFromNetwork (http://localhost:4200/ngsw-worker.js:657:27)
    at <anonymous>)
Latest manifest hash: 1e8cde0a19381fa6a01acbeefefa861865f34a1f
Last update check: 3s374u

=== Version 1e8cde0a19381fa6a01acbeefefa861865f34a1f ===

Clients: 

=== Idle Task Queue ===
Last update tick: 2s28u
Last update run: 3s380u
Task queue:


Debug log:

[8s401u] Error(Hash mismatch (cacheBustedFetchFromNetwork): http://localhost:4200/index.html: expected e5defb09b5dadd8903d71b868022bf69fc954f39, got 002a296589766e144eda3002b7feb8b6e5ee1ac5 (after cache busting), Error: Hash mismatch (cacheBustedFetchFromNetwork): http://localhost:4200/index.html: expected e5defb09b5dadd8903d71b868022bf69fc954f39, got 002a296589766e144eda3002b7feb8b6e5ee1ac5 (after cache busting)
    at PrefetchAssetGroup.cacheBustedFetchFromNetwork (http://localhost:4200/ngsw-worker.js:657:27)
    at <anonymous>) initializeFully for 1e8cde0a19381fa6a01acbeefefa861865f34a1f

@lacolaco
Copy link
Contributor Author

lacolaco commented Oct 29, 2017

@lacolaco
Copy link
Contributor Author

lacolaco commented Nov 7, 2017

At 5.0.0 stable, I finally get my offline cache!! I appreciate the team.

@lacolaco lacolaco closed this as completed Nov 7, 2017
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: service-worker Issues related to the @angular/service-worker package
Projects
None yet
Development

No branches or pull requests

4 participants