fix(codegen): dont return data from GetModuleHook in first pass, shuffle templates #272
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Stencil doesn't provide any guarantees around template rendering order.
This was a concious decision made to prevent overly complex templating
usecases where templates aren't the best place to encapsulate said
logic. However, in order for templates to be able to use module hooks,
we still needed the notion of an "add to hook" and "get hook" state.
This brought the two-pass render system that we have today. The first
render pass is for adding to module hooks while the second is for
retrieving module hook data. Only the results of the second pass are
used for writing to files on the filesystem.
However, due to an oversight in the original implementation, we never
actually limited the
GetModuleHook
function to return data just duringthe second pass. It returns data even during the first pass, which means
that it's possible to access data in a non-determisitic fashion during
the first pass. This commit changes that behaviour to have
GetModuleHook
always return[]any
during the first pass. Thisensures that there is never any order dependent module hook data being
returned.
Also as part of this, to prevent further accidental leakage of file
ordering, we now sort templates randomly on each stencil run. This
mirrors mentality behind the Go maps to help prevent developers from
relying on a certain key ordering.
As a reminder for reviewers, module hooks only write to the module hook
in-memory store during the first pass. They noop during the second pass.