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

fix: prerender optional parameters as empty when entries contains '*' #11178

Merged

Conversation

LorisSigrist
Copy link
Contributor

Closes #11133

Currently, any routes with parameters are only prerendered if they are discovered through crawling, or export entries.
This makes sense for required parameters, since it's not possible to know which values they accept otherwise.
For optional parameters, we do know that not passing a value is valid. With this PR routes with optional parameters that are marked as prerenderable will be crawled with no value by default.

Examples:

  • /some-route/[[optionalParam]]/a will be crawled with /some-route/a
  • /some-route/[[optionalParam]]/a/[[optionalParam2]]/b will be crawled with /some-route/a/b

A common situation where this causes frustration is on multi-langauge pages with a [[lang]] parameter at the root. In that case / won't be crawled. It needs to be manually specified in the entries, which feels silly.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat:, fix:, or chore:.

Copy link

changeset-bot bot commented Dec 2, 2023

🦋 Changeset detected

Latest commit: 37cfe14

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

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

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

@benmccann
Copy link
Member

Thanks for this!

The description of '*' should probably be tweaked to describe what happens with optional values: https://kit.svelte.dev/docs/configuration#prerender

I feel that creating a whole new test project is a bit overkill. It'd probably be better to refactor out a method that can be unit tested or add an optional route to an existing test project

@LorisSigrist
Copy link
Contributor Author

Will do!

@eltigerchino eltigerchino added the paths.base bugs relating to `config.kit.paths.base` label Dec 10, 2023
@benmccann benmccann removed the paths.base bugs relating to `config.kit.paths.base` label Dec 12, 2023
@benmccann benmccann added this to the 2.0 milestone Dec 12, 2023
@benmccann benmccann changed the base branch from master to version-2 December 12, 2023 18:05
@benmccann benmccann changed the title Crawl Optional Parameters without Value fix: prerender optional parameters as empty when entries contains '*' Dec 12, 2023
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

Successfully merging this pull request may close these issues.

Crawler doesn't discover / if there is an optional parameter at the base
3 participants