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

don't pass URL from server #3942

Merged
merged 4 commits into from
Feb 16, 2022
Merged

don't pass URL from server #3942

merged 4 commits into from
Feb 16, 2022

Conversation

Rich-Harris
Copy link
Member

The reasons for the previous way of doing things are somewhat cloudy — something to do with ensuring that we use the same route in the client as we do on the server, and with the same params, even if the page is prerendered and deployed somewhere that it doesn't expect to be.

But since those things are passed along separately, I think it's preferable to set the URL based on window.location — this means client-side access to search and hash (without weird hacks), and is arguably more correct, even if there is a risk of inconsistency in edge cases.

This will allow us to close #3650 and #3680.

No tests because it's a bit of an awkward thing to test for.

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 pnpx changeset and following the prompts. All changesets should be patch until SvelteKit 1.0

@changeset-bot
Copy link

changeset-bot bot commented Feb 15, 2022

🦋 Changeset detected

Latest commit: 25430e9

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

@Rich-Harris it looks like the tests are failing with this PR

@Rich-Harris
Copy link
Member Author

the adapter-static changes were a red herring, but worth keeping anyway

@Conduitry
Copy link
Member

Why is this adding devalue? Is that being used anywhere in these changes?

Co-authored-by: Ignatius Bagus <ignatius.mbs@gmail.com>
@Rich-Harris
Copy link
Member Author

Why is this adding devalue? Is that being used anywhere in these changes?

Yeah, it allows adapter-static to test using src/cli.js rather than dist/cli.js — initially I thought the failing tests were in that package, and that was part of my attempt to debug. I was wrong (it was the prerender tests inside Kit, which use adapter-static) but it felt like a good change to keep anyway.

I'd quite like to get rid of the devalue dependency separately — we're only using it to prevent XSS vulns in params and session, and we could use an internal helper instead if we were happy insisting session be JSON-serializable — but that would be a separate chunk of work.

params: ${devalue(params)}

function try_serialize(data, fail) {
try {
return devalue(data);
} catch (err) {
if (fail) fail(coalesce_to_error(err));
return null;
}
}

@Rich-Harris Rich-Harris merged commit 9bb08d7 into master Feb 16, 2022
@Rich-Harris Rich-Harris deleted the use-actual-url branch February 16, 2022 20:36
@benmccann benmccann mentioned this pull request Mar 5, 2022
5 tasks
@johnnysprinkles
Copy link
Contributor

I think this also fixes #1511. Rock on!

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.

page.url.searchParams not set on first page land with static build
5 participants