Blitz: The blitz dev cache must be busted if blitz version changes.

Created on 6 Nov 2020  路  11Comments  路  Source: blitz-js/blitz

What do you want and why?

Currently the .blitz dev cache is not cleared between blitz start invocations for performance. That's great, but we've found that when the blitz version changes we need to bust that cache.

https://github.com/blitz-js/blitz/issues/1407 is an example error caused by the lack of this.

Possible implementation(s)

Basically we want to clean the cache anytime the installed blitz version changes.

Setting this clean config item to true will clean the cache. That spot is a possible place to do this.

kinbug statudone

All 11 comments

Let me elaborate.

If blitz version in package.json is changed, we need to set clean in config to true right?

@rayandrews yes. So we need to cache the blitz version somehow inside .blitz so that each time blitz start runs, we can check the current blitz version with the cached version.

Also, we need to check the actual installed version of blitz, not just the version range in the app package.json. I think we can get the actual installed version with something like this:

const pkgJson = require(path.join(require.resolve('blitz'), 'package.json'))

I see, it makes sense now for the installed version @flybayer

However, how about the blitz version inside .blitz? Do we just use the package.json inside .blitz folder?

No, we don't currently store the blitz version. We could add a new file or maybe add a new field to .blitz/caches/dev/_manifest.json.

@ryardley any opinion on this?

I see, we can cache the version via this function

and re-read it while running in development to make sure the version is same or not @flybayer

Maybe we can store the blitz version in the cache hash?

could you give me the pointer of the cache hash?

I want to work on this.

is it similar like file-cache here or different?

@flybayer @ryardley

@rayandrews I was talking about the file tree hashing happening here: https://github.com/blitz-js/blitz/blob/canary/packages/server/src/build-hash.ts#L26

Looks like you can't add strings to hash object so I would be inclined to use a second hash function and hash the hash with the blitz version. eg. return sha1(tree.hash + blitzVersion);

CMIIW, hash runs only for production right?

so for summary:

  • hash the tree.hash with blitzVersion with sha1(tree.hash + blitzVersion)
  • add this feature to development
  • and the rest is same like production command (checking the hash etc)

am I right? @ryardley

Hmm maybe I am wrong and am misunderstanding this issue. If we are talking about a dev related thing. Yeah you might want to:

  1. Write a file with the blitz version to every build. Probably want to do it either asynchronously in the creation phase of a stage. Here is an example of how you can do that using the processNewFile function.
  2. Read that file when assembling config to calculate the clean flag.

Got it @ryardley.
I understand now thank you.

Count me in and I will make a PR.

Thank you @ryardley @flybayer

Best Regards

Was this page helpful?
0 / 5 - 0 ratings

Related issues

flybayer picture flybayer  路  3Comments

svobik7 picture svobik7  路  3Comments

SharadKumar picture SharadKumar  路  3Comments

netheril96 picture netheril96  路  4Comments

yhoiseth picture yhoiseth  路  3Comments