New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use git hash to break cache #1684
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pending @sunaurus’s feedback and the missing new line at the end of one of those files, this looks great and solves a huge bug. Fantastic!
Also, epic rhyme in PR title. |
What’s going on with CI here? Definitely would be great to get this in the next RC. |
webpack.config.js
Outdated
@@ -96,15 +101,15 @@ const createClientConfig = (_env, mode) => { | |||
entry: "./src/client/index.tsx", | |||
output: { | |||
filename: "js/client.js", | |||
publicPath: "/static/", | |||
publicPath: `/static/${commitHash}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
publicPath: `/static/${commitHash}` | |
publicPath: `/static/${commitHash}/` |
Without the trailing slash the paths break:
Unhandled Promise Rejection: ChunkLoadError: Loading chunk 76292 failed.
(error: http://localhost:1234/static/3caf913614868f70475430fca3dcc40c61d613b5js/76292.client.js)
This is totally optional, but IMO using the --short git hashes will be a bit nicer while still giving absurdly low chances of collisions. With With |
Sorry to complicate things, but couldn't we just do cache busting without git, eg. webpack config? |
I think the issue with webpack hashes is that we run the server and client webpack builds seperately, and I'm not sure if there's any clean way to take the resulting hash(es) from the client build, and replace them into imports in the generated server files. My assumption is that it would require a bigger refactor of the webpack configuration. But I'm no webpack expert, maybe there's some obvious way to do it that I'm missing! |
I think there's a way to export the |
@SleeplessOne1917 @sunaurus Ya that's an easy one to fix: In the
|
Okay actually I'm kinda changing my mind a bit: Check out this line: https://github.com/LemmyNet/lemmy-ui/blob/main/Dockerfile#L27 It should also set the commit hash there. Why not just let the webpack read the version / commit hash from the |
Pretty much this. The built in hashes for webpack were the first thing I tried, but I couldn't figure out how to use them in the actual code.
See the most recent commit I made. Using the hash is now docker agnostic, and it's set as an environment variable. |
Co-authored-by: Alec Armbruster <35377827+alectrocute@users.noreply.github.com>
src={avatar ?? "/static/assets/icons/icon-96x96.png"} | ||
src={ | ||
avatar ?? | ||
`/static/${process.env.COMMIT_HASH}/assets/icons/icon-96x96.png` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make this into a bundleFolder()
or bundleDir()
function? That way we won't have to trace all these down again potentially in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1. I vote for something like getStaticDir
and have it in @utils/env
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll make the change during my lunch break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made the changes.
Closes #1676