Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TemplateContentPrematureUseError for one specific post / date, only on start #3630

Open
forresto opened this issue Jan 23, 2025 · 3 comments

Comments

@forresto
Copy link

forresto commented Jan 23, 2025

Operating system

macOS 15.2

Eleventy

3.0.0

Describe the bug

[11ty] Unhandled rejection in promise:
[11ty] Tried to use templateContent too early on ./content/2020s/2023-studio-wall/index.md (via TemplateContentPrematureUseError)

Content of that post:

---
date: 2023-05-03
title: 2023 Studio Wall (annotated)
---

Content md...

Reproduction steps

I get the error when I first run npx @11ty/eleventy --serve (dev). That's the only post that gives that error.

If I comment out the data line...

# date: 2023-05-03

... it will actually start and serve the page, with the file created date. I can then uncomment the date: line and it rerenders and fixes the date.

It only throws on initial start.

npx @11ty/eleventy (build) hits the same error.

This is different than #3136 because it happens on startup, not rerender.

Expected behavior

No response

Reproduction URL

No response

Screenshots

No response

@forresto
Copy link
Author

forresto commented Jan 23, 2025

OK this is spooky, if I change to date: 2025-05-03 it starts. Is the 2023 date conflicting with the 2023- directory name somehow?

It only works with future dates. Even tomorrow.

@forresto
Copy link
Author

forresto commented Jan 23, 2025

Edit: it came back on a later run, so this didn't actually fix it.

I think it was due to the use of .getAllSorted() when adding my posts collection.

	eleventyConfig.addCollection("posts", function (collectionsApi) {
		const isPost = (item) => {
			const dir = item.filePathStem.split("/");
			const extension = item.inputPath.split(".").pop();
			return !item.data.isIndex && dir.length >= 3 && extension === "md";
		};
		return collectionsApi.getAllSorted().filter(isPost);
	});

Changing to .getAll() seems to fix it.

	eleventyConfig.addCollection("posts", function (collectionsApi) {
		const isPost = (item) => {
			const dir = item.filePathStem.split("/");
			const extension = item.inputPath.split(".").pop();
			return !item.data.isIndex && dir.length >= 3 && extension === "md";
		};
		return collectionsApi
			.getAll()
			.filter(isPost)
			.sort((a, b) => a.date - b.date);
	});

@forresto
Copy link
Author

forresto commented Jan 23, 2025

Disabling feedPlugin seems to fix it reproducibly. 🤞

I have "@11ty/eleventy-plugin-rss": "^2.0.3",

It must have something to do with the way that I set up the posts collection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant