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

[NEXT-1071] Static sitemap route is not optimized as static #48991

Closed
1 task done
arialpew opened this issue Apr 29, 2023 · 2 comments · Fixed by #49109
Closed
1 task done

[NEXT-1071] Static sitemap route is not optimized as static #48991

arialpew opened this issue Apr 29, 2023 · 2 comments · Fixed by #49109
Assignees
Labels
area: app App directory (appDir: true) linear: next Confirmed issue that is tracked by the Next.js team. Metadata Related to Next.js' Metadata API.

Comments

@arialpew
Copy link

arialpew commented Apr 29, 2023

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: win32
      Arch: x64
      Version: Windows 10 Pro
Binaries:
      Node: 20.0.0
      npm: N/A
      Yarn: N/A
      pnpm: N/A
Relevant packages:
      next: 13.3.2
      eslint-config-next: 13.3.1
      react: 18.2.0
      react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

App directory (appDir: true), Metadata (metadata, generateMetadata, next/head, head.js)

Link to the code that reproduces this issue

Install a standard Next.js setup v13.3.2 and use static export + new appDir and add an app/sitemap.ts file.

next.config.js file :

/** @type {import('next').NextConfig} */
const nextConfig = {
  output: 'export',
  pageExtensions: ['ts', 'tsx', 'js', 'jsx'],
  reactStrictMode: true,
  swcMinify: true,
  // Note: This feature is required to use NextJS Image in SSG mode.
  // See https://nextjs.org/docs/messages/export-image-api for different workarounds.
  images: {
    unoptimized: true,
  },
  experimental: {
    appDir: true,
  },
}

To Reproduce

  • Static export output mode.
  • Using the new appDir experimental.
  • Version 13.3.2 (currently latest version).
  • Windows 10 (no WSL).

When running npm run build, sitemap isn't generated. In development mode, the sitemap is accessible.

app/sitemap.ts file :

import { MetadataRoute } from 'next'
import { allBlogs } from '@/.contentlayer/generated'

export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
  const blogs = allBlogs.map(post => ({
    url: `http://localhost:3000/blog/${post.slug}`,
    lastModified: post.publishedAt,
  }))

  const routes = ['', '/blog', '/contact'].map(route => ({
    url: `http://localhost:3000${route}`,
    lastModified: new Date().toISOString().split('T')[0],
  }))

  return [...routes, ...blogs]
}

Build log :

Route (app)                                Size     First Load JS
┌ ○ /                                      175 B          81.7 kB
├ ● /blog/[slug]                           2.5 kB           84 kB
├   ├ /blog/post-0002
├   └ /blog/post-0001
├ ○ /robots.txt                            0 B                0 B
└ λ /sitemap.xml/[[...__metadata_id__]]    0 B                0 B
+ First Load JS shared by all              75.9 kB
  ├ chunks/139-95fe43fc14e42daa.js         23.6 kB
  ├ chunks/2443530c-dfeca1b6f38a1e91.js    50.5 kB
  ├ chunks/main-app-06da1dca58d74c34.js    214 B
  └ chunks/webpack-d9bdffe382ff608b.js     1.69 kB

Route (pages)                              Size     First Load JS
─ ○ /404                                   178 B            86 kB
+ First Load JS shared by all              85.8 kB
  ├ chunks/main-470121997414b370.js        83.9 kB
  ├ chunks/pages/_app-c544d6df833bfd4a.js  192 B
  └ chunks/webpack-d9bdffe382ff608b.js     1.69 kB

λ  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
○  (Static)  automatically rendered as static HTML (uses no initial props)
●  (SSG)     automatically generated as static HTML + JSON (uses getStaticProps)

As you can see, sitemap end up with a weird filename /sitemap.xml/[[...__metadata_id__]] and it didn't write to the file system. Robots is fine, but sitemap doesn't end up in the out folder in production build.

Describe the Bug

A sitemap isn't generated in the out folder when runnning npm run build.

Expected Behavior

A sitemap should be generated in the out folder when runnning npm run build.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

From SyncLinear.com | NEXT-1071

@arialpew arialpew added the bug Issue was opened via the bug report template. label Apr 29, 2023
@github-actions github-actions bot added area: app App directory (appDir: true) Metadata Related to Next.js' Metadata API. labels Apr 29, 2023
@huozhi huozhi self-assigned this Apr 29, 2023
@huozhi huozhi added linear: next Confirmed issue that is tracked by the Next.js team. and removed bug Issue was opened via the bug report template. labels Apr 29, 2023
@huozhi huozhi changed the title Sitemap not generated [NEXT-1071] Sitemap not generated Apr 29, 2023
@arialpew
Copy link
Author

arialpew commented May 1, 2023

Since the sitemap work in development but isn't generated in production build (where we opted for static export), I suspect it's not because of filename or filesystem write, but more about the fact that Next.js consider the sitemap as "server-side renders at runtime" - but it should not, this conflict with the static export in next.config.js, hence the issue.

@huozhi huozhi changed the title [NEXT-1071] Sitemap not generated [NEXT-1071] Static sitemap route is not optimized as static May 2, 2023
@kodiakhq kodiakhq bot closed this as completed in #49109 May 2, 2023
kodiakhq bot pushed a commit that referenced this issue May 2, 2023
…49109)

* For sitemap if they're not using dynamic routes generation `generateSitemaps`, should optimize them as static sitemap
* For icons and social images, if they're not using `generateImageMetadata`, should optimize them as static path

Closes NEXT-1071
Fixes #48991
@github-actions
Copy link
Contributor

github-actions bot commented Jun 2, 2023

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: app App directory (appDir: true) linear: next Confirmed issue that is tracked by the Next.js team. Metadata Related to Next.js' Metadata API.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants