-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(codegen): dont return data from GetModuleHook in first pass
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 during the 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. This ensures 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.
- Loading branch information
1 parent
f05cd8a
commit 2330940
Showing
5 changed files
with
29 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
{{ index (stencil.GetModuleHook "coolthing") 0 }} | ||
{{- $mh := stencil.GetModuleHook "coolthing" }} | ||
{{ if $mh }}{{ index $mh 0 }}{{ end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters