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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature?]: Make paths starting with / go to the SERVER_BASE_URL #1383

Open
2 tasks done
birkskyum opened this issue Mar 12, 2024 · 5 comments
Open
2 tasks done

[Feature?]: Make paths starting with / go to the SERVER_BASE_URL #1383

birkskyum opened this issue Mar 12, 2024 · 5 comments
Labels
enhancement New feature or request

Comments

@birkskyum
Copy link
Contributor

birkskyum commented Mar 12, 2024

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Summary 馃挕

I have ported a static docs site from an older solid-start-static to the Vinxi version of SolidStart, and what I found was that it's still necessary to append the baseURL virtually everywhere there is an asset or link.

Current situation:

  • all assets like <img> or favicon needs to manually have appended ${import.meta.env.SERVER_BASE_URL}
  • the <Router base={import.meta.env.SERVER_BASE_URL} /> is needed to make the <A /> work
  • anchors in markdown or <a> needs the ${import.meta.env.SERVER_BASE_URL}/page.

Suggestion:

  • It would be great if all links with a root url like /page or /img.png would contain the baseURL, so that it wouldn't have to be injected in any of these three cases.

Examples 馃寛

No response

Motivation 馃敠

No response

@birkskyum birkskyum added the enhancement New feature or request label Mar 12, 2024
@birkskyum birkskyum changed the title [Feature?]: Make links starting with / go to the SERVER_BASE_URL [Feature?]: Make urls starting with / go to the SERVER_BASE_URL Mar 12, 2024
@birkskyum birkskyum changed the title [Feature?]: Make urls starting with / go to the SERVER_BASE_URL [Feature?]: Make paths starting with / go to the SERVER_BASE_URL Mar 12, 2024
@ryansolid
Copy link
Member

Interesting. I wasn't aware of this behavior especially on anchors. We need the base URL to be able to remove it from the path. Like anchors aside the router needs it. <A> always added it on. So I'm guessing it removed and adds it again. But the fact this could fix <a> in these scenarios is interesting.

Was this something we were doing in our Vite plugin though?.. Because I'd be super surprised if this was default behavior. I guess Vite does a transform on the HTML (their whole index.html thing) and we must have been tapping into that. Thanks this makes is easier to at least understand where the gap is.

@birkskyum
Copy link
Contributor Author

birkskyum commented Mar 12, 2024

@ryansolid , seem like i remembered wrong - there was no such behavior of injecting base path in anchors in the past, but it would be big dx improvement to have.

@nksaraf
Copy link
Member

nksaraf commented Mar 12, 2024

not possible to inject stuff arbitrary outside the html, most of the anchors, imgs, etc are being rendered via the JSX. If they are not A they are not even javascript code run for them that we can do something on the runtime. If you are app is at a base path not /, you would need to account for that in your assets/links etc if you're client runtime is not handling it (so for eg. solid's router can do it for A, but who will do it for a plain img?)

@birkskyum
Copy link
Contributor Author

birkskyum commented Mar 12, 2024

I don't know how it works, or if JSX is the limiting factor here, but if I look at a project like this Nuxt 3 demo:
https://github.com/lucpotage/nuxt-github-pages

It has a baseURL: '/nuxt-github-pages/',.

image

The two pages Home and About contain images like this:
<img src="/qingbao-meng-01_igFr7hd4-unsplash.jpg" loading="lazy">.

When i run npm run generate, the index.html contains an image tag that suddenly looks like this:
<img src="/nuxt-github-pages/qingbao-meng-01_igFr7hd4-unsplash.jpg" loading="lazy">

<A />

The anchors are written as <NuxtLink to="/about">About</NuxtLink>, so no <Router base /> wrapper, and after generation it comes out as <a href="/nuxt-github-pages/about" class="">About</a>


It also works if i run npm run build and node .output/server/index.mjs instead of the ssg

Lowercase <a /> doesn't get this baseURL appended though.

@ryansolid
Copy link
Member

ryansolid commented Apr 11, 2024

The only way I could see consistently being able to make that transformation is if the image is being imported and then processed as an asset via vite. That could work as it would move it to the assets location and get that interesting hash rewrite. But I don't think we could just parse some arbitrary string. Is that like Nuxt special image component or something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants