question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Remove 'navigateFallback' behavior from default SW config

See original GitHub issue

I wanted to move my latest comments from https://github.com/facebookincubator/create-react-app/issues/2398#issuecomment-334227447 into a specific issue to discuss them separate from the larger meta-conversation around service workers in create-react-app:

Here’s one possible change that could be made short of removing service worker generation: by default, index.html is used to handle all navigation requests for URLs that aren’t precached (config).

This behavior is in there to support SPA-style offline usage, where users might navigate to URLs that don’t correspond to underlying HTML files. That being said, many developers don’t fall into that category.

What we could do is remove navigateFallback/navigateFallbackWhitelist completely from the default configuration. Offline usage for index.html and any other files that exist as part of the Webpack build will still work. Offline usage for SPA-style routing will continue to work if hash-based routing is used (as opposed to pushState routing).

The drawback is that getting offline support with pushState routing working would require an eject and re-adding navigateFallback to the config, but at least there’s a specific place in the existing documentation for this use case, where we can clearly spell out the changes that are needed.

Given that it would break the “navigate to a random URL and expect it to work” offline experience for any SPAs that have gone through the steps to support the History API’s pushState(), I think that if we move forward, it needs to wait until the next major release of create-react-app.

@chee has put together https://github.com/facebookincubator/create-react-app/pull/3024 which would be sufficient in terms of a code change, but we’d need to accompany it with changes to the docs explaining how to eject and re-enable that behavior for SPAs using the History API (which I’m happy to write).

CC: @Timer @gaearon @addyosmani for their thoughts.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
cheecommented, Nov 6, 2017

i wouldn’t have minded the burden! i love burden

but it’s now closed in favour of yours

thanks! it looks like a good move.

Read more comments on GitHub >

github_iconTop Results From Across the Web

workbox-build - Chrome Developers
An optional array of regular expressions that restricts which URLs the configured navigateFallback behavior applies to. This is useful if only a subset...
Read more >
How to you modify the precache manifest file generated by ...
1 Answer 1. Sorted by: Reset to default. Highest score (default) ...
Read more >
Top 5 sw-precache Code Examples - Snyk
Learn more about how to use sw-precache, based on sw-precache code examples created from the most popular ways it is used in public...
Read more >
sw-precache-webpack-plugin | Yarn - Package Manager
mergeStaticsConfig : [boolean] - Merge provided staticFileGlobs and stripPrefixMulti with webpack's config, rather than having those take precedence, default is ...
Read more >
Offline caching with Service Worker Precache - Polymer Project
Configure fallback using the navigateFallback and navigateFallbackWhitelist parameters. Example sw-precache-config.js module.exports = { staticFileGlobs: [ '/ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found