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

Astro.url.pathname includes trailing dash when building for SSG but not on dev mode #5630

Closed
1 task
pilcrowonpaper opened this issue Dec 18, 2022 · 5 comments · Fixed by #8068
Closed
1 task
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) semver: major Change triggers a `major` release

Comments

@pilcrowonpaper
Copy link
Contributor

What version of astro are you using?

1.7.1

Are you using an SSR adapter? If so, which one?

none

What package manager are you using?

npm

What operating system are you using?

Mac

Describe the Bug

Astro.url.pathname returns a different value on dev mode (dev command) and build command.

// src/pages/hello-word.astro
Astro.url.pathname === "/hello-world"; // dev mode
Astro.url.pathname === "/hello-world/"; // build

Link to Minimal Reproducible Example

https://github.com/pilcrowOnPaper/astro-trailling-dash

Participation

  • I am willing to submit a pull request for this issue.
@bluwy
Copy link
Member

bluwy commented Dec 19, 2022

I believe this was intentional depending on the build.format config (since that option was added), but I had find this confusing too, and ideally would be nice if it's consistent.

@bluwy bluwy added the - P3: minor bug An edge case that only affects very specific usage (priority) label Dec 19, 2022
@williamhzo
Copy link

been facing the same bug, if i'm not mistaken there was a discussion about this in #4190, and the TL;DR was:

Ok, we do have consensus now. We will make the build follow build.format so that if it is set to directory (the default), your url will be /page/ and if it is set to file it will be page.html. This should make relative URLs created using Astro.url work as you would want/expect.

but i don't think it solves the inconsistency in the default behaviour between dev and build.

mvllow added a commit to rose-pine/rose-pine-site that referenced this issue Apr 18, 2023
This commit replaces Astro local styles with tailwind equivalents.

Due to `Astro.url.pathname` inconsistencies between development and
production (see withastro/astro#5630), we
strip the trailing slash when doing comparisons against the current
pathname.
@teleclimber
Copy link

teleclimber commented Apr 22, 2023

I am experiencing this too. This doesn't seem like a "minor bug". All my links work in dev and preview, but are broken in prod because of this. A relative link defined in /page.md like this:

[blah](destination)

...goes to /destination in dev and preview, and it goes to /page/destination/ in prod. The result is I have 404s all over my deployed site and I'm not sure how to fix it apart from changing every link to be absolute.

I just upgraded all packages and verified it's still happening. Astro 2.3.0 used for pure SSG.

Edit: I've figured out how to fix by setting build.format as mentioned above, and I have to change a number of my links to make it all work. The issue remains that this behavior is confusing and error-inducing.

mvllow added a commit to rose-pine/rose-pine-site that referenced this issue Apr 24, 2023
This commit replaces Astro local styles with tailwind equivalents.

Due to `Astro.url.pathname` inconsistencies between development and
production (see withastro/astro#5630), we
strip the trailing slash when doing comparisons against the current
pathname.
@bluwy
Copy link
Member

bluwy commented May 25, 2023

Similar issue: #6623. It would be a breaking change if we fix this, so will also mark it as so if we get around it in the next major.

@matthewp
Copy link
Contributor

I don't think this is a bug. If you are using trailingSlash: 'ignore' then you are saying that you'll accept either with or without a trailing slash. But it sounds like you want it to not have the trailing slash, in which case you should be using trailingSlash: 'never'. Am I missing something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P3: minor bug An edge case that only affects very specific usage (priority) semver: major Change triggers a `major` release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants