ricokahler / next-plugin-preval

Pre-evaluate async functions during builds and import them like JSON
MIT License
255 stars 12 forks source link

Data can be stale after the first load #23

Closed ricokahler closed 3 years ago

ricokahler commented 3 years ago

A user of this plugin recently asked if the plugin caches because the data did not refresh on a page reload during development.

This issue occurs as a consequence of how webpack works and how it caches resources during development.

During development, webpack will cache a resource it has already loaded before and will only re-compile that source if it sees a change in the contents of the file loaded. In the case of prevals, the file doesn’t actually change but the data does.

This is known issue on my side and there are ways to fix it but it involves having the data source send some sort of event to tell webpack to re-compile the preval’ed file.

For now, workarounds are:

  1. touch the preval file (e.g. hit save). the update to the file is enough to tell webpack to refresh the preval.
  2. restart the dev server.

A better solution would most likely involve creating a mechanism for data sources to tell webpack to refresh the file (or maybe just polling). I'm open to any suggestions!

RamZallan commented 3 years ago

@ricokahler as an update to this, restarting the dev server does not fix the cacheing problem. I've had to either touch the file, or delete the .next directory.

Also, I host my site on Netlify, where I have to manually select Clear cache and deploy site to have the changes reflected -- since they aren't when a build is triggered via git. This causes a bit of a problem when I'm trying to use build hooks, where clearing the cache isn't an option.

github-actions[bot] commented 3 years ago

:tada: This issue has been resolved in version 1.0.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

github-actions[bot] commented 3 years ago

:tada: This issue has been resolved in version 1.0.2-alpha.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

github-actions[bot] commented 3 years ago

:tada: This issue has been resolved in version 1.2.0-alpha.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: