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

Sitemap await not... well, waiting... #141

Open
petethered opened this issue Aug 13, 2024 · 5 comments
Open

Sitemap await not... well, waiting... #141

petethered opened this issue Aug 13, 2024 · 5 comments

Comments

@petethered
Copy link

I'm trying to convert a SSG to SSR and found your extension which has been solving some of my sitemap issues. Thanks!

That being said, I'm running into issues trying to pull a list of ids to include in the sitemap for

During build, the await for fetch doesn't seem to be waiting.

[id].astro

import { fetchIds } from "../../data/items";
import sitemap from 'sitemap-ext:config';
sitemap(async ({ addToSitemap }) => {
  console.log("PreFetch");
  const ids = await fetchIds();
  console.log(ids);
  addToSitemap(
    ids?.data?.ids?.map((post) => ({
      id: post,
    }))
  );
});

items.ts

  try {
    console.log(`http://server/staticGenerator/items?allId=1`);
    const response = await fetch(`http://server/staticGenerator/items?allId=1`);
    console.log("Res: ", response);
    
    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }
    
    const data = await response.json();
    return data;
  } catch (error) {
    console.error("Error", error);
    return {};
  }
};

Running build shows the "PreFetch", and the url in the console log, but nothing happens... the request isn't made.

Mind telling me what I'm missing?

@Fryuni
Copy link
Owner

Fryuni commented Aug 15, 2024

Nothing immediately jumps to me as missing or wrong; that should be working.

I'll try to reproduce it locally and fix it. Thanks for reporting 😄

@petethered
Copy link
Author

Thanks!

I can throw together a small project to be a full replication if you'd like. It's really just the one line

const response = await fetch(`http://server/staticGenerator/items?allId=1`);

That's the issue and not running during the build.

I BELIEVE i tried copying the fetch call directly into the sitemap(async instead of using external, but the external is getting invoked just there's no wait for the promise... it just bails out silently.

@Fryuni
Copy link
Owner

Fryuni commented Aug 16, 2024

Is the server the project being built or something external?

@petethered
Copy link
Author

It's an external URL (ie http://example.com/staticGenerator/items?allId=1)

I've tried building on both local and having cloudflare build it.

I've made sure no experimental flags are enabled.

I upgraded to the latest astro.

    "@astrojs/tailwind": "^5.1.0",
    "@faker-js/faker": "^7.3.0",
    "astro": "^4.14.2",
    "daisyui": "^4.4.23",
    "globby": "^11.0.4",
    "prettier": "^2.8.8",
    "prettier-plugin-astro": "^0.0.12"
  },
  "dependencies": {
    "@astrojs/cloudflare": "^11.0.4",
    "@astrojs/preact": "^3.5.1",
    "@astrojs/react": "^3.6.2",
    "@astrojs/sitemap": "^3.1.6",
    "@inox-tools/sitemap-ext": "^0.3.2",
    "@preact/signals": "^1.3.0",
    "@types/react": "^18.0.10",
    "@types/react-dom": "^18.0.5",
    "astro-tabs": "^0.1.8",
    "astro-vtbot": "^1.8.4",
    "preact": "^10.23.1",
    "sass": "^1.69.5"
  }
import preact from "@astrojs/preact";
import tailwind from "@astrojs/tailwind";

//import sitemap from "@astrojs/sitemap";
import sitemap from '@inox-tools/sitemap-ext';

// https://astro.build/config
import cloudflare from "@astrojs/cloudflare";

// https://astro.build/config
export default defineConfig({
// Enable React to support React JSX components.
experimental: {
//  contentCollectionCache: true
},
site: 'https://recentmusic.com',
integrations: [preact(), tailwind({
  config: {
    path: "./tailwind.config.js"
  }
}), sitemap({
  includeByDefault: true,
})],
output: "server",
adapter: cloudflare()
});

@petethered
Copy link
Author

https://github.com/petethered/sitemap-ext-test-case

Here you go, full replication case.

https://github.com/petethered/sitemap-ext-test-case/blob/main/src/pages/divisions/%5Bid%5D.astro

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

No branches or pull requests

2 participants