Skip to content

Conversation

@Rich-Harris
Copy link
Member

Closes #3955. This throws an error in the case where a page links to /a#b and /a doesn't include an element with id="b".

We probably want to make that behaviour configurable somehow, since some people might want a warning rather than an error, or even custom error handling. For normal prerendering errors this is enabled via config.kit.prerender.onError, but the API can't accommodate these errors. I'm not really sure what to do about that, so I'm just going to leave this in draft for now.

Also not pictured: tests of funky IDs that involve URL or HTML encoding. No idea if that works in this branch currently but either way it needs tests.

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. All changesets should be patch until SvelteKit 1.0

@changeset-bot
Copy link

changeset-bot bot commented Oct 24, 2022

🦋 Changeset detected

Latest commit: d1431c2

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

@Rich-Harris
Copy link
Member Author

The deploy failure is because this is working — it's identified an incorrect link

@Rich-Harris
Copy link
Member Author

This replaces config.kit.prerender.onError with config.kit.prerender.handleHttpError, to distinguish it from the new config.kit.prerender.handleMissingId.

Remaining question is whether the default for config.kit.prerender.handleMissingId should be fail or warn. Thoughts?

Copy link
Member

@dummdidumm dummdidumm left a comment

Choose a reason for hiding this comment

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

Apart from a minor naming (which I'm ok with if you turn it down) thing this looks good!

Comment on lines 167 to 170
const expected_deeplinks = new Map();

/** @type {Map<string, string[]>} */
const actual_deeplinks = new Map();
Copy link
Member

Choose a reason for hiding this comment

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

I was confused for a moment because I understand a regular link to not just the home page by "deeplink", I think something like "hashlink" would be better.

Copy link
Member Author

Choose a reason for hiding this comment

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

agree — fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validate hash links when prerendering

4 participants