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

Package not working with Next.js 15 (Async Request APIs) #895

Open
piotrkulpinski opened this issue Nov 5, 2024 · 5 comments
Open

Package not working with Next.js 15 (Async Request APIs) #895

piotrkulpinski opened this issue Nov 5, 2024 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@piotrkulpinski
Copy link

Hi,

I just upgraded Next.js to v15, and the next-sitemap package stopped working. The request API is now async, which seems to disrupt the sitemap generation functionality.

Has anyone managed to get sitemaps working with Next 15?

Thanks!

@piotrkulpinski piotrkulpinski added the bug Something isn't working label Nov 5, 2024
@mezotv
Copy link

mezotv commented Nov 11, 2024

Personally I just use nextjs native sitemap feature nowadays since this library is not maintained anymore.

@Hahlh
Copy link

Hahlh commented Nov 13, 2024

@mezotv I don't think that's accurate anymore: #865

@mezotv
Copy link

mezotv commented Nov 13, 2024

@mezotv I don't think that's accurate anymore: #865

Fair enough, hopefully the lib is working again soon!

@rtatarinov
Copy link

@iamvishnusankar any updates from you? It would be so nice if you implement nextjs15 support into this package

@dymoo
Copy link

dymoo commented Dec 14, 2024

Personally I just use nextjs native sitemap feature nowadays since this library is not maintained anymore.

Next sitemap doesn't allow for sitemap index generation and I've had problems creating 'force-dynamic' sitemaps, sitemap.ts doesn't seem to respect export const dynamic...

I've written my own mini version of this lib if any one wants to copy paste.

import { NextResponse } from "next/server";

export function buildSitemapIndex(sitemaps: string[]) {
  let xml = '<?xml version="1.0" encoding="UTF-8"?>';
  xml += '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';

  for (const sitemapURL of sitemaps) {
    xml += "<sitemap>";
    xml += "<loc>";
    xml += sitemapURL;
    xml += "</loc>";
    xml += "</sitemap>";
  }

  xml += "</sitemapindex>";

  return new NextResponse(xml, {
    headers: {
      "Content-Type": "application/xml",
      "Content-Length": Buffer.byteLength(xml).toString(),
    },
  });
}

type TSitemapEntry = {
  priority?: number;
  loc: string;
  changefreq?:
    | "always"
    | "hourly"
    | "daily"
    | "weekly"
    | "monthly"
    | "yearly"
    | "never";
  lastmod?: Date;
};

export function buildSitemap(items: TSitemapEntry[]) {
  let xml = '<?xml version="1.0" encoding="UTF-8"?>';
  xml += `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">`;

  for (const item of items) {
    xml += "<url>";
    xml += "<loc>" + item.loc + "</loc>";
    if (item.lastmod) {
      xml += "<lastmod>";
      xml += item.lastmod.toISOString();
      xml += "</lastmod>";
    }
    if (item.changefreq) {
      xml += "<changefreq>";
      xml += item.changefreq;
      xml += "</changefreq>";
    }
    if (item.priority) {
      xml += "<priority>";
      xml += item.priority;
      xml += "</priority>";
    }
    xml += "</url>";
  }

  xml += "</urlset>";

  return new NextResponse(xml, {
    headers: {
      "Content-Type": "application/xml",
      "Content-Length": Buffer.byteLength(xml).toString(),
    },
  });
}

ibn4 template literals are the same speed as concatenation...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants