Skip to content

fix: default SourceLoader config.FS to LocalFS(/) (#5) - #6

Merged
panyam merged 1 commit into
mainfrom
fix/source-loader-nil-fs-issue-5
Jun 17, 2026
Merged

panyam merged 1 commit into
mainfrom
fix/source-loader-nil-fs-issue-5

Conversation

@panyam

@panyam panyam commented Jun 17, 2026

Copy link
Copy Markdown
Owner

Summary

  • Closes SourceLoader: nil config.FS escapes relative includes to process CWD and causes Path collisions #5.
  • NewSourceLoader now defaults config.FS to NewLocalFS("/") when nil. Loaded template Paths become absolute (no collision between local and vendored templates that share a basename) and relative includes resolve under the configured template root instead of the process CWD.
  • Un-skips TestSourceLoader_RelativePathsInVendoredTemplates (already covered case 1) and adds TestSourceLoader_LocalAndVendoredSameBasename for case 2.

Reviewer's guide

  • source_loader.go — the only behavior change: nil-FS default in NewSourceLoader. NewSourceLoaderFromConfig already resolves search paths to absolute, so they compose cleanly with a root-mounted LocalFS.
  • vendoring_test.go — two tests exercising the fix paths.

Test plan

  • go test -run 'TestSourceLoader_RelativePathsInVendoredTemplates|TestSourceLoader_LocalAndVendoredSameBasename' -v — both pass.
  • go test -short ./... — full suite green.
  • Downstream verify: bump templar in lilbattle and confirm WorldListingPage renders without the loader errors.

NewSourceLoader left config.FS nil when callers didn't set it, which broke
two scenarios:

1. Relative includes (e.g. `./Header.html`) inside templates escaped to the
   process working directory. FSFolder.resolve fell back to NewLocalFS rooted
   at the bare cwd string, so includes were searched under the process CWD
   instead of the configured template root.
2. A local template and a @vendor-namespaced template sharing the same base
   name (e.g. BasePage.html) collided on Template.Path, tripping Walker's
   cycle guard and silently dropping the namespace load.

Default config.FS to NewLocalFS("/") when nil so absolute search paths and
vendor dirs resolve through one shared FS, loaded Paths are unique absolute
paths, and relative includes stay anchored under the template root.

Un-skips TestSourceLoader_RelativePathsInVendoredTemplates and adds
TestSourceLoader_LocalAndVendoredSameBasename to cover both regressions.
@panyam
panyam merged commit 536ff4c into main Jun 17, 2026
1 check passed
@panyam
panyam deleted the fix/source-loader-nil-fs-issue-5 branch June 17, 2026 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SourceLoader: nil config.FS escapes relative includes to process CWD and causes Path collisions

1 participant