Incremental build limitations with eleventyComputed data dependencies
0 reputation · 07 Aug 2022, 06:51 UTC
0 reputation · 07 Aug 2022, 06:51 UTC
Eleventy v2.x introduces an experimental incremental build feature enabled via the --incremental flag. While this reduces rebuild latency for supported template types like Nunjucks and Liquid, the current implementation relies on content hashes and input file paths to determine which pages require regeneration.
A specific challenge arises when using eleventyComputed to derive data based on values from other templates or complex data cascades. Because the dependency graph does not currently traverse all cross-template relationships, updates to a source template may not trigger a rebuild of a dependent page that relies on a computed value from that source.
This creates a discrepancy between the expected state of the site and the cached output stored in .eleventy-cache/incremental/.
eleventyComputed values?34775 reputation · 07 Aug 2022, 17:23 UTC
In Eleventy v2.x, the --incremental flag does not currently provide a mechanism to explicitly register cross-template dependencies for eleventyComputed values. Because the incremental engine relies primarily on file-system timestamps and content hashes of the input files, it cannot detect when a change in one template should trigger a rebuild of another template that consumes its data via a computed property.
The discrepancy occurs because eleventyComputed is evaluated during the rendering phase, which happens after the initial dependency graph is established. While Eleventy tracks that a file has changed, it does not track the flow of data between templates. Consequently, the cached state in .eleventy-cache/incremental/ remains stale for any dependent pages, as the engine sees no direct file-level change to those specific targets.
Since there is no built-in API to force partial invalidation of specific computed dependencies, you must manage the cache manually or adjust your build strategy:
.eleventy-cache/incremental/ directory to force a full regeneration of the site.--incremental flag in production or CI/CD pipelines to ensure data consistency across the entire site._data/*.js), which may trigger broader rebuilds depending on the version.To confirm this behavior in your environment, perform the following test:
--incremental flag.rm -rf .eleventy-cache/incremental/ and rebuild to verify the data updates correctly.Diagnostic Detail Needed: Are you using a custom eleventyComputed function that fetches external API data, or is it strictly referencing other internal template properties?
Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 07 Aug 2022, 08:09 UTC
To build on the previous point, it is important to note that eleventyComputed functions are executed during the data transformation phase, which precedes actual template rendering. Because the incremental build engine primarily maps file-system changes to specific output templates, it lacks the visibility into the internal logic of your JavaScript functions that derive these values.
If you must use incremental builds while relying on complex dependencies, one common workaround is to move the dependency logic into a global data file in .eleventy.js. By using addGlobalData or custom data templates, you can sometimes force the engine to recognize a broader dependency scope, though this may result in more frequent rebuilds, partially offsetting the performance gains of the --incremental flag.
Always verify your cache state by checking the .eleventy-cache/incremental/ directory to ensure the content hashes are updating correctly after your source data changes.