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

addGlobalData should execute once per build, currently executing once per template file #2179

Closed
zachleat opened this issue Jan 18, 2022 · 5 comments
Assignees
Labels

Comments

@zachleat
Copy link
Member

cc @dleatherman

@zachleat zachleat added the bug label Jan 18, 2022
@zachleat zachleat added this to the Eleventy 1.0.1 milestone Jan 18, 2022
@zachleat zachleat self-assigned this Jan 18, 2022
@dleatherman
Copy link

dleatherman commented Jan 18, 2022

Describe the bug

Plugin (and addGlobalData) should run once per build, not once per template file.

To Reproduce

I created a simplified version of the bug here: https://github.com/dleatherman/eleventy-plugin-async-test where the build outputs 3 console logs (one for each of the layouts).

  1. Clone above repo
  2. npm install && cd demo && npm install && npm run build
  3. See output from plugin and async function (1 time for each template file: base.njk, index.njk, and page.njk)
  4. See error

Expected behavior

I would expect the plugin (or addGlobalData) to run once per eleventy build, not once per template file. I am awaiting content and then building individual pages via pagination. Each of the pages generated via pagination gets another instance of the plugin's function run causing my build to continue calling the content API exponentially.

Environment:

  • OS and Version: Mac OS (12)
  • Eleventy Version 1.0.0

Additional Context

Possibly related to #1729

@mattbloomfield
Copy link

Hi @zachleat any idea on timing for this? It's causing me to hit quota limits about 100x faster than I should using Firebase for storage.

@pdehaan
Copy link
Contributor

pdehaan commented Feb 7, 2022

@mattbloomfield Not a direct answer to your question, but a couple approaches I've used in the past:

  • using https://www.11ty.dev/docs/plugins/cache/ for caching network requests, or
  • move the API requests outside of eleventy into a separate Node/Bash script so I can download a bunch of data, do some light processing, and then storing the results (as a big ol' JSON blob) in the /_data/ directory. Sometimes this is easier because the data I'm scraping might only change daily so there's no need to always refetch locally while debugging, etc.
    • Then i can just run npm run fetchdata whenever I need to update the random data I'm using.

@zachleat
Copy link
Member Author

zachleat commented Feb 15, 2022

This will go up with v1.0.1!

Newest possible canary: 1.0.1-canary.3

@dleatherman
Copy link

Stellar! Thank you!!

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

No branches or pull requests

4 participants