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

Warn when getStaticPaths exists without a prerender statement #7713

Merged
merged 13 commits into from
Jul 19, 2023

Conversation

natemoo-re
Copy link
Member

@natemoo-re natemoo-re commented Jul 18, 2023

Changes

Testing

We don't have (reliable) tests for CLI logs, unfortunately

Tested manually

Docs

cc @withastro/maintainers-docs for feedback on the warning message. These warnings aren't something we document like our errors, but they are user-facing!

Before

[getStaticPaths] getStaticPaths() in /src/pages/posts/[slug].astro is ignored when "output: server" is set.

After

[getStaticPaths] The getStaticPaths() statement in /src/pages/posts/[slug].astro has been ignored.

Add `export const prerender = true;` to prerender this page.

@changeset-bot
Copy link

changeset-bot bot commented Jul 18, 2023

🦋 Changeset detected

Latest commit: 13fa4f4

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Jul 18, 2023
Copy link
Member Author

@natemoo-re natemoo-re left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tweaking the getStaticPaths without prerender warning so it runs during dev and build. Previously, it only ran when a page was being rendered in dev.

Comment on lines -35 to -41
if (ssr && mod.getStaticPaths && !route.prerender) {
warn(
logging,
'getStaticPaths',
`getStaticPaths() in ${bold(route.component)} is ignored when "output: server" is set.`
);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of checking this at runtime like we do here...

Comment on lines 43 to 47

// `getStaticPaths` warning is just a string check, should be good enough for most cases
if (!pageOptions.prerender && isServerLikeOutput(settings.config) && code.includes('getStaticPaths')) {
warn(logging, "getStaticPaths", `The getStaticPaths() statement in ${bold(rootRelativePath(settings.config.root, fileURL, true))} has been ignored.\n\nAdd \`export const prerender = true;\` to prerender this page.`);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check has been moved to compile time (in our astroScannerPlugin).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated this one per @sarah11918's feedback that mentioning output: "${mode}" would be helpful.

@natemoo-re natemoo-re marked this pull request as ready for review July 18, 2023 21:02
Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the move to compile/build-time warnings!

Copy link
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the new warning! Nice that it includes a helpful actionable step of how to fix.

@natemoo-re natemoo-re merged commit d088351 into main Jul 19, 2023
@natemoo-re natemoo-re deleted the fix/6350--plt-561 branch July 19, 2023 14:33
@astrobot-houston astrobot-houston mentioned this pull request Jul 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prerendering from Content Collections still adds content to SSR server code
4 participants