Skip to content

feat: Add a speedier script tag for prerendered redirects#9911

Merged
Rich-Harris merged 8 commits intomasterfrom
elliott/9907-speeeeeeeed
May 16, 2023
Merged

feat: Add a speedier script tag for prerendered redirects#9911
Rich-Harris merged 8 commits intomasterfrom
elliott/9907-speeeeeeeed

Conversation

@elliott-with-the-longest-name-on-github
Copy link
Contributor

@elliott-with-the-longest-name-on-github elliott-with-the-longest-name-on-github commented May 12, 2023

Closes #9907.

TODO:

  • I'm not sure I landed on the right solution for encoding URIs. It passes the tests... but I'm not sure that means it's good.

(I also deleted some empty +page.svelte files, which used to be required but now are not)

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:.

@changeset-bot
Copy link

changeset-bot bot commented May 12, 2023

🦋 Changeset detected

Latest commit: b1af08e

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

@elliott-with-the-longest-name-on-github
Copy link
Contributor Author

Looks like I missed a few tests; will have to go back and fix 'em

Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>
Copy link
Member

@Rich-Harris Rich-Harris left a comment

Choose a reason for hiding this comment

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

i feel good about the encoding, but this has historically been a blind spot of mine so i'd be happy to wait for others to weigh in (@Conduitry is particularly adept at heading off string encoding bugs)

@Conduitry
Copy link
Member

Hm. What specifically are we trying to handle by doing encodeURI(decodeURIComponent(...))? I'm worried about that losing the encoding on some characters that we actually need it for.

Since " and \ and < are all encoded by encodeURI, I think we're safe from injection attacks here. But I am still worried about ending up on the wrong URL. For example, a %40 in the original URL would end up a @ in the location.href= string.

Can we instead do a straight string escaping thing of location like we do for the values that get serialized into the inline <script> tag that starts the app on regular pages? Note that this is not just JSON.stringify() because there are some additional characters that need to be escaped to be safe. Even using devalue should work if we don't have another function for this hanging around anywhere, although it would definitely be overkill. It being overkill might not matter so much, since this is done at build time anyway, not runtime.

@elliott-with-the-longest-name-on-github
Copy link
Contributor Author

Thanks @Conduitry -- the reason we were doing a decode/encode is to avoid double-encoding. That being said, I think you're right about just string-escaping it. I'm not going to have time to do this today or tomorrow, so I'll probably get it done on Monday.

@elliott-with-the-longest-name-on-github
Copy link
Contributor Author

@Conduitry -- mind taking a look now that we're using devalue.uneval?

Co-authored-by: Conduitry <git@chor.date>
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.

Redirect from prerendered pages with <script>

4 participants