Skip to content

Commit 9923f79

Browse files
committed
Revert "Remove the navigateFallback behavior from the generated service worker (facebook#3419)"
This reverts commit b6aebb9. # Conflicts: # packages/react-scripts/template/README.md
1 parent 0e51eef commit 9923f79

File tree

2 files changed

+18
-31
lines changed

2 files changed

+18
-31
lines changed

packages/react-scripts/config/webpack.config.prod.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -442,12 +442,13 @@ module.exports = {
442442
console.log(message);
443443
},
444444
minify: true,
445+
// For unknown URLs, fallback to the index page
446+
navigateFallback: publicUrl + '/index.html',
447+
// Ignores URLs starting from /__ (useful for Firebase):
448+
// https://github.com/facebookincubator/create-react-app/issues/2237#issuecomment-302693219
449+
navigateFallbackWhitelist: [/^(?!\/__).*/],
445450
// Don't precache sourcemaps (they're large) and build asset manifest:
446451
staticFileGlobsIgnorePatterns: [/\.map$/, /asset-manifest\.json$/],
447-
// `navigateFallback` and `navigateFallbackWhitelist` are disabled by default; see
448-
// https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#service-worker-considerations
449-
// navigateFallback: publicUrl + '/index.html',
450-
// navigateFallbackWhitelist: [/^(?!\/__).*/],
451452
}),
452453
// Moment.js is an extremely popular library that bundles large locale files
453454
// by default due to how Webpack interprets its code. This is a practical

packages/react-scripts/template/README.md

+13-27
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ You can find the most recent version of this guide [here](https://github.com/fac
8383
- [Static Server](#static-server)
8484
- [Other Solutions](#other-solutions)
8585
- [Serving Apps with Client-Side Routing](#serving-apps-with-client-side-routing)
86-
- [Service Worker Considerations](#service-worker-considerations)
8786
- [Building for Relative Paths](#building-for-relative-paths)
8887
- [Azure](#azure)
8988
- [Firebase](#firebase)
@@ -1839,14 +1838,8 @@ is integrated into production configuration,
18391838
and it will take care of generating a service worker file that will automatically
18401839
precache all of your local assets and keep them up to date as you deploy updates.
18411840
The service worker will use a [cache-first strategy](https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#cache-falling-back-to-network)
1842-
for handling all requests for local assets, including
1843-
[navigation requests](https://developers.google.com/web/fundamentals/primers/service-workers/high-performance-loading#first_what_are_navigation_requests)
1844-
for `/` and `/index.html`, ensuring that your web app is consistently fast, even
1845-
on a slow or unreliable network.
1846-
1847-
>Note: If you are using the `pushState` history API and want to enable
1848-
cache-first navigations for URLs other than `/` and `/index.html`, please
1849-
[follow these steps](#service-worker-considerations).
1841+
for handling all requests for local assets, including the initial HTML, ensuring
1842+
that your web app is reliably fast, even on a slow or unreliable network.
18501843
18511844
### Opting Out of Caching
18521845
@@ -2049,27 +2042,20 @@ If you’re using [Apache Tomcat](http://tomcat.apache.org/), you need to follow
20492042
20502043
Now requests to `/todos/42` will be handled correctly both in development and in production.
20512044
2052-
When users install your app to the homescreen of their device the default configuration will make a shortcut to `/`. This may not work if you don't use a client-side router and expect the app to be served from `/index.html`. In this case, the web app manifest at [`public/manifest.json`](public/manifest.json) and change `start_url` to `./index.html`.
2053-
2054-
### Service Worker Considerations
2055-
2056-
[Navigation requests](https://developers.google.com/web/fundamentals/primers/service-workers/high-performance-loading#first_what_are_navigation_requests)
2057-
for URLs like `/todos/42` will not be intercepted by the
2058-
[service worker](https://developers.google.com/web/fundamentals/getting-started/primers/service-workers)
2059-
created by the production build. Navigations for those URLs will always
2060-
require a network connection, as opposed to navigations for `/` and
2061-
`/index.html`, both of which will be served from the cache by the service worker
2062-
and work without requiring a network connection.
2063-
2064-
If you are using the `pushState` history API and would like to enable service
2065-
worker support for navigations to URLs like `/todos/42`, you need to
2066-
[`npm eject`](#npm-run-eject) and enable the [`navigateFallback`](https://github.com/GoogleChrome/sw-precache#navigatefallback-string)
2045+
On a production build, and in a browser that supports [service workers](https://developers.google.com/web/fundamentals/getting-started/primers/service-workers),
2046+
the service worker will automatically handle all navigation requests, like for
2047+
`/todos/42`, by serving the cached copy of your `index.html`. This
2048+
service worker navigation routing can be configured or disabled by
2049+
[`eject`ing](#npm-run-eject) and then modifying the
2050+
[`navigateFallback`](https://github.com/GoogleChrome/sw-precache#navigatefallback-string)
20672051
and [`navigateFallbackWhitelist`](https://github.com/GoogleChrome/sw-precache#navigatefallbackwhitelist-arrayregexp)
20682052
options of the `SWPreachePlugin` [configuration](../config/webpack.config.prod.js).
20692053
2070-
>Note: This is a [change in default behavior](https://github.com/facebookincubator/create-react-app/issues/3248),
2071-
as earlier versions of `create-react-app` shipping with `navigateFallback`
2072-
enabled by default.
2054+
When users install your app to the homescreen of their device the default configuration will make a shortcut to `/index.html`. This may not work for client-side routers which expect the app to be served from `/`. Edit the web app manifest at [`public/manifest.json`](public/manifest.json) and change `start_url` to match the required URL scheme, for example:
2055+
2056+
```js
2057+
"start_url": ".",
2058+
```
20732059
20742060
### Building for Relative Paths
20752061

0 commit comments

Comments
 (0)