mars/create-react-app-buildpack

Need to Re-deploy after setting Env Vars

s2t2 opened this issue · 3 comments

s2t2 commented

Hi, thanks for this great buildpack. It has really made deploying react apps much easier!

However, I am experiencing some behavior possibly related to this issue, where a re-deploy is required AFTER setting REACT_APP_ env vars in order for them to be recognized on Heroku.

Steps to reproduce:

  1. Add some code to your react app which references and prints an env var, like var API_URL = process.env.REACT_APP_API_URL || "http://localhost:5000".
  2. Then commit and deploy the code to heroku via git push heroku master.
  3. Then set the env var via heroku config:set REACT_APP_API_URL="my-api-url"
  4. When you visit the site, you'll see it not recognize the env var.

After re-deploying again AFTER setting the env var, you'll see it works.

Desired behavior:

When I set an env var on Heroku, perhaps the build should be re-triggered or something, so a re-deploy is not necessary.

Version:

I believe I'm using the most recent version of this buildpack, but not sure how to check. This is the output from heroku buildpacks:versions mars/create-react-app:

Version  Released At               Status
───────  ────────────────────────  ─────────
7        2019-03-11T14:43:39.712Z  published
6        2018-12-23T16:31:59.674Z  published
5        2018-10-08T20:48:34.131Z  published
4        2018-10-02T16:59:42.585Z  published
3        2018-09-23T20:00:49.383Z  published
2        2018-09-11T18:31:36.419Z  published
1        2018-05-30T18:32:49.395Z  published
mars commented

Did you try using the Runtime Environment Variables feature?

s2t2 commented

I see. However to stay consistent with the normal Heroku environment variable experience, I recommend that any setting of REACT_APP environment variables will trigger a re-build. Is that possible?

mars commented

Sorry @s2t2 no, that's not possible from the buildpack perspective.

There are ways you could probably finagle behavior like that:

  • use a custom webhook processor to trigger rebuilds
    • trade-off: additional custom async service complexity to create/maintain your custom release behavior
  • always rebuild on dyno start-up by putting your JS build command in .profile
    • trade-off: slow dyno start-up times which will timeout after 60secs.

Neither of those is "normal Heroku" and each has massive trade-off.