Skip to content

Remove 'navigateFallback' behavior from default SW config #3248

Closed
@jeffposnick

Description

@jeffposnick

I wanted to move my latest comments from #2398 (comment) 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 #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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions