withastro / adapters

Home for Astro's core maintained adapters
66 stars 37 forks source link

Astro Netlify adapter with on-demand builder not caching #4

Closed x71c9 closed 11 months ago

x71c9 commented 1 year ago

What version of astro are you using?

2.8.3

Are you using an SSR adapter? If so, which one?

Netlify

What package manager are you using?

yarn

What operating system are you using?

Linux

What browser are you using?

Chromium

Describe the Bug

Reading the documentation it seems it is possible to use Netlify On-Demand builder to build pages on demand and then cache them on the Netlify CDN.

I tried to implement this feature but it doesn't seem to work.

Here is my code:

// astro.config.mjs

import { defineConfig } from 'astro/config';
import netlify from "@astrojs/netlify/functions";

// https://astro.build/config
export default defineConfig({
  output: "server",
  adapter: netlify({
    builders: true,
  })
});
# netlify.toml

[build]
  command = "yarn build"
  publish = "dist"
// src/pages/index.astro

---
import Layout from "../layouts/Layout.astro";

const response = await new Promise((resolve, reject) => {
  setTimeout(() => {
    resolve(7);
  }, 2000)
});
---

<Layout title="Welcome to Astro">
  <main>MAIN {response}</main>
</Layout>

The setTimeout is for emulating an async method that takes some time.

After deploying with:

ntl deploy --prod

I see the page waiting 2 seconds before delivering the HTML.

However I would expect the Netlify On-Demand Builder to cache it and then not wait 2 seconds anymore.

I checked on Netlify support and a Support Engineer answer with this: https://answers.netlify.com/t/astro-adapter-with-on-demand-builder-not-caching/96756/4?u=ndr4

That site is not using On Demand Builders. It has a single redirect that’s redirecting to /.netlify/functions/entry. Paths at /.netlify/functions are not builder functions. This is an Astro issue. They need to redirect to /.netlify/builders.

Is this true? Is this a bug in the Astro Netlify adapter library?

What's the expected result?

When I call the URL the On-demand builder cache the response. The second time I call the same URL the CDN respond with the cached version.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-zfmbew?file=astro.config.mjs

Participation

ematipico commented 1 year ago

@x71c9 I used the reproduction, and when I run npm run build, the adapter creates a dist/_redirects that has the correct content:

/       /.netlify/builders/entry    200

You need to give us a correct reproduction to help you.

github-actions[bot] commented 1 year ago

Hello @x71c9. Please provide a minimal reproduction using a GitHub repository or StackBlitz. Issues marked with needs: repro will be closed if they have no activity within 3 days.

natemoo-re commented 1 year ago

Sorry for the automated comment, I can see that we properly generate a redirect to the /.netlify/builders/entry file, but that file doesn't seem to exist in the generated bundle.

Sounds like a regression on our end.

ematipico commented 1 year ago

@natemoo-re I believe that's a stackblitz thing that hides dot folders. I just used a local project on mine, and the assets are correctly emitted.

ematipico commented 1 year ago

I deployed my pet project to netlify and I can't see the headers that usually identify builders. Meaning, their value is always miss.

alexanderniebuhr commented 11 months ago

Can we confirm that this is still an issue.

alexanderniebuhr commented 11 months ago

Closing for now, because the Issue seems to be stale. Happy to reopen, if we get new information or confirmation.