-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
🐛 BUG: Astro.url.pathname is missing trailing slash on prod build #4190
Comments
related to #3959 by @FredKSchott (reviewed by @matthewp and @tony-sull), who may have an opinion about this |
Thanks for opening an issue! This definitely sounds like a problem. If you're willing to open a PR, we'll definitely make time to review it. Otherwise we'll try to get this prioritized as soon as we can. |
@natemoo-re thank you for the feedback. Which solution do you think is the best?
I would prefer the second option, since it is more consistent and easier to implement correctly. |
I just wanted to say that I hit this bug as well just now. I have some logic for my nav links that compare the pathname from the current page to the href of the link, and Percy.io noticed that my active page link was no longer being highlighted. I think now that 1.0 has been released, the first option has to be used to avoid a breaking change, right? Otherwise, folks like me would need to go through and update the logic to remove trailing slashes, and not expect them even when they're in the url in the browser. |
Since the current behavior (as of 1.0) is to have the paths without trailing slash on (so 1.0 was a breaking change and we now have to change “serve” to be coherent) |
Oh interesting, I'm still getting trailing slashes in 1.0.5... |
@IanVS is your issue getStaticPaths related? |
@oliverpool in dev Astro.url.pathname should be matching what you typed into the browser. If that is not the case then please let me know. Build mode is trickier to answer If you have |
@matthewp no I'm not using
in my astro layout's frontmatter. On a page like
In both cases, the url is the same in the address bar. And I don't have |
@IanVS Thank you for the specifics! Correct me if I'm wrong, but does |
In dev, the Dev:
Prod:
Is that what you were asking? |
I think so. Is the file |
The |
@matthewp I think everything is documented into my first post (with a Minimal Reproducible Example):
It does. But my main issue is with Maybe the To sum up, my issue is that |
Thanks for all of the feedback! I agree that there's a problem here, just trying to understand the nuance in order to find the correct solution.
As you pointed out, Let me know if this would work for you @oliverpool @IanVS. I'm going to consult with the core team to see if this idea makes sense to them as well. |
Yep, that would work great on my end, thanks. |
Sounds good to me. A couple of remarks:
|
Yeah that's an interesting point. |
Talked about this with core and we are not comfortable with changing the defaults now that 1.0 is out. Even though I don't like the mismatch here either, some users are likely depending on the default-no-slash behavior that currently exists. What should be working is that if you set Also the docs will be updated because although they say the config is for the dev server, it's a top-level config and should be applied to both dev and build. |
If that's the case, it might also be good to note that the replacement of |
Too bad that this issue got attention after the 1.0 release (this issue was opened 2 days before the release). If you don't want to change it, it means that you consider the current behavior to be |
There were a lot of changes between the late betas and the final release, which went very quickly. I'm really surprised how many breaking changes were made late in the game. Definitely a bummer that there wasn't more time for community feedback. 😞 |
To be fair, I don't think there's any breaking change here. The mistake, to me, is making We can and should fix this in 2.0. I'm not closing this issue until we have that figured out. A 2.0 is not necessarily a long way out. I do take all feedback about the instability in the beta/RC period. We didn't do a great job of planning on breaking changes and then make them all at once; instead we allowed ourselves to continue to find things we wanted to change until close to the 1.0 release. We've heard this feedback from a lot of the community (and among ourselves) and will work to not do this the next time around. Part of that is not breaking apps now, though. So as much as I personally do not like the current behavior, breaking it for everyone else today is not the right answer. I think the right answer is to make sure |
Ok, the team has been talking about this again and now I think our opinion is changing based on the |
Ok, we do have consensus now. We will make the build follow Thanks to you both @oliverpool @IanVS for making a strong case here and being patient with me. I hope to get this into a patch fix soon. |
PR: #4352 |
#4404 My current problem is that when reading the |
Am I correct that if you converted an existing site to Astro that uses essentially directory with no trailing slash, you cannot get Astro.url.pathname to remove the slash? The original idea of following |
So, it seems like the default behavior has since been changed, because I'm getting the opposite of the behavior @IanVS describes in this comment above: in dev, presence of trailing slash matches address bar, in prod, trailing slash always there (no I get that at build time, Astro has to decide one way or the other what But even after reading all the comments above, I still don't understand why there's a difference in behavior between dev and prod. I guess dev mode is trying to be more "smart" by generating routes/pages on the fly based on what's requested? But I'd much prefer consistent behavior between dev and prod, so I'm not caught off guard by these types of issues (another example I ran into a while back). I'd like to discover them before deployment. I guess the fact that Astro is a framework that can deploy in many different "modes" makes this more complicated... Perhaps dev mode is running in a way that reflects the "server" mode? But doesn't Astro know which way the app is meant to be built and served ahead of time, and couldn't it match the behavior between dev and prod? |
What version of
astro
are you using?1.0.0-rc.7
Are you using an SSR adapter? If so, which one?
none
What package manager are you using?
yarn
What operating system are you using?
archlinux
Describe the Bug
I just upgraded to
1.0.0-rc.1
and got a warning aboutAstro.canonicalURL.pathname
(which I am using to highlight selected menu).I replaced its usage with
Astro.url.pathname
and everything looked fine withastro dev
.However when doing the static build with
astro build
the menu does not get highlighted.With some debugging, it turns out, that
Astro.url.pathname
:dev
(with a trailing slash if the URL has one - and not otherwise)build
there is never a trailing slash (even if the URL has one - somehow expected, since the sameindex.html
file is served)Looking at the (now deleted) code of
createCanonicalURL
https://github.com/withastro/astro/pull/3959/files#diff-7d09784396a04fa12dd4dcfbe9d6f7528bfe522487493851dc08957000481facL6 the added trailing slash has been dropped.A proper fix would:
dev
to match the URL which would be used forbuild
(with a trailing slash to match the behavior before RC, without if you think this would be better)What do you think?
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-mz4j6y?file=src/pages/test.astro
Navigate to the following URLs:
/test
<- will be the onastro build
)/test/
)Participation
The text was updated successfully, but these errors were encountered: