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 Redirect issue when using baseURL #1584

Closed
wants to merge 17 commits into from

Conversation

sidharthv96
Copy link
Contributor

@sidharthv96 sidharthv96 commented May 29, 2021

Closes #1583
Fixes #1476

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

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

* 'master' of https://github.com/sveltejs/kit:
  Version Packages (next) (sveltejs#1543)
  type fixes for adapter-node and adapter-static (sveltejs#1578)
  Upgrade to Vite 2.3.3 (sveltejs#1580)
  fix: improve getRawBody parsing & handle error(s) (sveltejs#1528)
  create-svelte: add svelte-check for TS (sveltejs#1556)
  pass validated svelte config to adapters (sveltejs#1559)
  types: group related and reduce potential inconsistencies (sveltejs#1539)
  Use sveltekit tag on StackOverflow (sveltejs#1558)
  Fix create-svelte build-template script (sveltejs#1555)
  Remove err param from Polka .listen() callback (sveltejs#1550)
  bump: polka and sirv versions (sveltejs#1548)
  svelte-kit package (sveltejs#1499)
* 'master' of github.com:sidharthv96/kit:
  chore: Add changeset for favicon
  Add favicon to skeleton template
@sidharthv96 sidharthv96 changed the title Fix Redirect issue when using baseURL #1583 Fix Redirect issue when using baseURL May 29, 2021
@sidharthv96

This comment has been minimized.

@sidharthv96

This comment has been minimized.

@sidharthv96
Copy link
Contributor Author

Should I be adding tests to packages/kit/test/apps/basics/src/routes/routing/_tests.js ?

@sidharthv96
Copy link
Contributor Author

Seems like all the tests are running with a config with empty paths.base.

Got this when I grepped the output after logging the config being passed to the tests.

"base": "",
"base": "",
"base": "",
"base": "",

Is there any tests which utilise 2 configs which I can refer to ?

@dummdidumm
Copy link
Member

I think you need to create a new top-level-app so to speak (below tests) where you can create a svelte.config with a baseUrl

* upstream/master:
  Add favicon to skeleton template (sveltejs#1514)
@sidharthv96
Copy link
Contributor Author

@dummdidumm Tried creating a new app, but it's failing when I try to load /basePath/valid.

I'm adding that folder into this PR. I've named it aa-routing just so that it's run first and I can see failures fast.

@@ -242,7 +242,7 @@ export class Router {

if (incorrect) {
info.path = has_trailing_slash ? info.path.slice(0, -1) : info.path + '/';
history.replaceState({}, '', `${info.path}${location.search}`);
history.replaceState({}, '', `${this.base}${info.path}${location.search}`);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the main fix in the PR.
Rest are UX improvements for CLI/Config validations.

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.

thank you — just left a few comments

packages/kit/src/cli.js Outdated Show resolved Hide resolved
@@ -0,0 +1,12 @@
<!DOCTYPE html>
Copy link
Member

Choose a reason for hiding this comment

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

rather than creating a new top-level app, could we move these into test/apps/options? it will mean updating the paths in the existing tests in that app, but i think that's preferable to creating a new app, since that will have a noticeable impact on how long tests take to run overall

.changeset/soft-bikes-bake.md Outdated Show resolved Hide resolved
@sidharthv96
Copy link
Contributor Author

@Rich-Harris the Options tests have been modified. But they still won't pass as the base path is not properly used in the dev and build servers.
I tried adding the base config in vite server, that did fix some tests, but broke others.
When I tested this with my app, index page would not load and threw The server is configured with a public base URL of /mermaid-live-editor/ - did you mean to visit /mermaid-live-editor/mermaid-live-editor instead? which came from a vite middleware.
https://github.com/sveltejs/kit/pull/1584/files#diff-ed48923f0655f935bee505cdcbf40212129ff49a89c2c9d752bd63aa1e6282c4

@Rich-Harris
Copy link
Member

Ah, of course — the base path isn't reflected locally during dev (or ideally during preview — #1154 / #1155), and as such the tests shouldn't account for it.

We could change that behaviour so that the base path is reflected, I haven't spent much time thinking about which is preferable. Either way, in the meantime we should a) remove the tests from this PR, and b) remove all the base occurrences in cli.js, leaving just the changes in load_config and client/router.js.

@sidharthv96
Copy link
Contributor Author

Raised #1608 with just the changes mentioned.

@benmccann
Copy link
Member

@sidharthv96 thanks for you contribution. I merged your other PR together with a related one. If you'd like to continue with this one it would need to be rebased now

@benmccann
Copy link
Member

@sidharthv96 did you want to rebase and continue with this PR or close it?

* 'master' of github.com:sidharthv96/kit: (1114 commits)
  Version Packages (next) (sveltejs#1858)
  Bump vite-plugin-svelte to 1.0.0-next.12 (sveltejs#1869)
  [fix] preserve user defined config and files on `svelte-kit package` (sveltejs#1735)
  [fix] handle undefined body on endpoint output (sveltejs#1808)
  [fix] copy essentials files from root on packaging (sveltejs#1747)
  [docs] sort config alphabetically (sveltejs#1867)
  add config.kit.package.emitTypes option (sveltejs#1852)
  [fix] add $lib alias to js/tsconfig (sveltejs#1860)
  Pass along custom properties added to Error (sveltejs#1821)
  Version Packages (next) (sveltejs#1840)
  Improve grammar in packages FAQ
  Docs for writing an adapter (sveltejs#1846)
  Additional documentation around pnpx changeset usage
  [feat] expose Vite.js `mode` from `$app/env` (sveltejs#1789)
  Service worker files exclusion support (sveltejs#1645)
  chore: Enable `vite.server.fs.strict` internally by default (sveltejs#1842)
  Test with the latest version of Svelte (sveltejs#1848)
  [docs] don't need to run pnpm install twice
  Improve HN example docs
  [fix] correct `ReadOnlyFormData` generator implementation (sveltejs#1837)
  ...
@changeset-bot
Copy link

changeset-bot bot commented Jul 11, 2021

⚠️ No Changeset found

Latest commit: d1179e2

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@benmccann
Copy link
Member

@sidharthv96 this PR would still need to be rebased. I may close this PR as stale if I don't hear from you. In that case we can always reopen later

…ePath

* 'master' of https://github.com/sveltejs/kit: (85 commits)
  [chore] minor simplification of `parse_body` (sveltejs#2043)
  Version Packages (next) (sveltejs#2026)
  [chore] deduplicate config types (sveltejs#2030)
  [chore] remove invalid css declaration (sveltejs#2038)
  [fix] correctly pass Vite options in preview mode (sveltejs#2036)
  [feat] Ignore adapter build files (sveltejs#1924)
  [chore] Upgrade Rollup
  Don't check external links on prerender (sveltejs#1679)
  Version Packages (next) (sveltejs#2017)
  [chore] convert remaining type aliases (sveltejs#2018)
  [feat] explicitly set compilerOptions.hydratable to config.kit.hydrate (sveltejs#2024)
  [feat] More powerful and configurable rendering options (sveltejs#2008)
  [chore] typecheck example (sveltejs#2019)
  Change config `prerender.force` to `prerender.onError` (sveltejs#2007)
  [chore] prefer interfaces to types (sveltejs#2010)
  [docs] minor wording improvement in migration guide (sveltejs#2006)
  [chore] test debugging improvements
  [docs] fix typo (sveltejs#2003)
  [chore] use @ts-expect-error instead of @ts-ignore (sveltejs#1999)
  Version Packages (next) (sveltejs#1996)
  ...
@sidharthv96
Copy link
Contributor Author

Ah, of course — the base path isn't reflected locally during dev (or ideally during preview — #1154 / #1155), and as such the tests shouldn't account for it.

We could change that behaviour so that the base path is reflected, I haven't spent much time thinking about which is preferable. Either way, in the meantime we should a) remove the tests from this PR, and b) remove all the base occurrences in cli.js, leaving just the changes in load_config and client/router.js.

@Rich-Harris should the behaviour be changed to reflect base path ?

@Rich-Harris
Copy link
Member

Now that I take another look at this I'm actually unclear what problem it solves. #1583 appears to be a duplicate of #1476, which was fixed by #1666. Am I missing something, or can this be closed? Thanks

@benmccann
Copy link
Member

I'm going to go ahead and close this since there hasn't been any response. We can reopen if necessary

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.

Redirect issue when using baseURL navigate always discard base path
4 participants