3

We have a web application (frontend) using React created from Create React App. The app is running on Google Cloud Platform App Engine Standard. Our web application is code splitted. Each page is then loaded on user navigation.

It's working really well. The issue we have is for example user A is on the app home page. We deploy a fix that change the chunk file name. The user A then try to access another page and then got the error Loading chunk * failed. The url to get the file is now returning a 404 because the file has been replaced by some new chunk files.

It's a frequent problem as I can see during my research but I didn't find a solution that apply for Google App Engine.

Here's an article that explain the problem / solution: https://mitchgavan.com/code-splitting-react-safely/

I would like to use the solution "Solution 1: Keep old files on your server after a deployment" but I can't see how to do this using GCP ...

Here's the app.yaml file

service: frontend
runtime: nodejs14
env: standard
instance_class: F1

handlers:
  - url: /(.*\..+)$
    static_files: build/\1
    upload: build/(.*\..+)$
  - url: /.*
    static_files: build/index.html
    upload: build/index.html

We have the following dispatch file (* for masked url)

dispatch:
  - url: "*"
    service: frontend

  - url: "www.*"
    service: frontend

1 Answers1

1

Haven't tried this before but see if it makes sense/works.

  1. We have a blog article about downloading your source code from GAE. It contains an explanation of where your source is stored when you deploy (a staging bucket), how long it stays there and how you can modify how long it stays before Google automatically deletes it.

  2. When you deploy to GAE, gcloud only deploys files that have changed (it doesn't deploy those that haven't). Since you now have 'new' files because new hashes were generated, the older files no longer exist on your local machine. I do not know if Google will automatically delete those files from the staging location in bullet 1 above.

  3. My proposal here is that you follow the steps in the blog article (from bullet 1) and alter (change) how long the files are retained in your staging bucket. Another option is to check the retention policy tab and see if you can change the rule so the files don't get deleted. If you're able to alter how long the files remain or the retention policy, it just might solve your problem. Let me know if this works

NoCommandLine
  • 5,044
  • 2
  • 4
  • 15