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: set trailing slash on data request 🛤 #9738

Conversation

dreitzner
Copy link
Contributor

@dreitzner dreitzner commented Apr 20, 2023

fixes #9595
Trailing slash was never set for preloading data through someroute/__data.json

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

Sorry, something went wrong.

Verified

This commit was signed with the committer’s verified signature.
dtolnay David Tolnay
@changeset-bot
Copy link

changeset-bot bot commented Apr 20, 2023

🦋 Changeset detected

Latest commit: 5c63a9c

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

@dreitzner dreitzner marked this pull request as ready for review April 20, 2023 20:38
@benmccann benmccann changed the title fix-9595: set trailing slash on data request 🛤 fix: set trailing slash on data request 🛤 Apr 20, 2023
@@ -962,6 +962,16 @@ test.describe('Routing', () => {
expect(await page.textContent('h1')).toBe('symlinked');
});
}
test('__data.json - trailing slash always', async ({ request }) => {
Copy link
Member

@benmccann benmccann Apr 20, 2023

Choose a reason for hiding this comment

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

This isn't testing trailingSlash: 'always': https://github.com/sveltejs/kit/blob/99891b80238ed4cf107012480ce6a473949bc28a/packages/kit/test/apps/basics/svelte.config.js. If you intend it to then the test needs to live in a different test project. If you don't then we can rename.

the other tests all have a blank line before them. let's keep that up for consistency. also I think the test name doesn't quite follow the pattern of the others

Suggested change
test('__data.json - trailing slash always', async ({ request }) => {
test('can load __data.json when trailing slash is present', async ({ request }) => {

Copy link
Contributor Author

@dreitzner dreitzner Apr 21, 2023

Choose a reason for hiding this comment

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

@benmccann

  1. line break is corrected
  2. added a better decription to the test
  3. the trailing slash config can be found here: packages/kit/test/apps/basics/src/routes/routing/trailing-slash-ssr/always/+page.js

The thing I'm trying to test, is the correct trailing slash in the pathname in __data.json, as it currently always falls back to never. (see #9595 (comment))

const data = await r.json();
expect(data.nodes[1].data[1]).toBe('/routing/trailing-slash-ssr/always/');
});
test('__data.json - trailing slash never', async ({ request }) => {
Copy link
Member

@benmccann benmccann Apr 20, 2023

Choose a reason for hiding this comment

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

Suggested change
test('__data.json - trailing slash never', async ({ request }) => {
test('can load __data.json when trailing slash is absent', async ({ request }) => {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Has a better name now

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.

Code changes look good, thank you! Only the tests need some tweaking.

'@sveltejs/kit': patch
---

fix: trailing slash on \_\_data.json request
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fix: trailing slash on \_\_data.json request
fix: compute trailing slash for data requests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added a better description for changeset

test('trailing slash is correct in url.pathname in __data.json (always)', async ({ request }) => {
const r = await request.get('/routing/trailing-slash-ssr/always/__data.json');
const data = await r.json();
expect(data.nodes[1].data[1]).toBe('/routing/trailing-slash-ssr/always/');
Copy link
Member

Choose a reason for hiding this comment

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

This relies on the internal structure of the __data.json requests. Can we instead do a more high-level test which is:

  1. start on trailing-slash-ssr (btw I would rename this to trailing-slash-server)
  2. use link clicks to go to different page with trailingSlash config
  3. test that the element that prints $page.url.pathname / returned data.pathname have the desired value

Basically similar to the current routing/trailing-slash tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dummdidumm

  1. changed folder name
  2. used click navigation
  3. updated tests to check for values in elements

I hope the changes reflect what you imagined 😊

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.

Thank you!

@dummdidumm dummdidumm merged commit 1bfcc7a into sveltejs:master Apr 25, 2023
@github-actions github-actions bot mentioned this pull request Apr 25, 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.

trailingSlash ignore gives wrong URL pathname
3 participants