question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Dynamic URLs don't use `basePath` correctly

See original GitHub issue

Are you reporting a bug?

Yes

The basePath (and stagingBasePath and devBasePath) works fine for the static URLs that are generated in .html files, but URLs that are dynamically created via JavaScript don’t use basePath correctly. Sometimes they leave it off altogether. Other times they repeat it twice.

Related (but different) issues:

Environment

  1. react-static -V: 6.2.0
  2. node -v: 10.11.0
  3. npm -v: 6.4.1
  4. Operating system: Windows 10
  5. Browser and version (if relevant): Chrome 71

Steps to Reproduce the problem

  1. Create a new project using the “basic” template

  2. Add the following to the static.config.json

  basePath: "PRODUCTION",
  stagingBasePath: "STAGING",
  devBasePath: "DEV",
  1. Run the dev server (npm start) and see that everything works correctly
  • (although it’s served from / not /DEV see Issue #972)
  1. Do a staging build (npm run stage)

  2. Move the contents of the dist folder to dist/STAGING to match our site config

mv dist STAGING
mkdir dist
mv STAGING dist/STAGING
  1. Remove the -s option from the serve script in package.json. That option causes problems due to the 404 issue that I’m demonstrating here.

  2. Run the static server (npm run serve)

  • The site is served from /STAGING and not from /. This is good because it accurately tests whether our site will work correctly in a non-root directory. 👍
  1. Open your browser dev tools and look at the “Network” tab.
  • Try to browse to a few different pages of the site. You’ll see a lot of 404 errors.

  • All the URLs in the .html files are correctly prefixed with /STAGING and work correctly

  • URLs that are loaded dynamically via JavaScript are mostly broken.

    • Some are missing the base path (e.g. /templates/src-pages-404.xxxxx.js)

    • Some have the base path twice (e.g. /STAGING/STAGING/about/routeinfo.json)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
DDunccommented, Feb 28, 2019

@tannerlinsley, Please reopen when you get the chance, thanks!

We’re also experiencing this issue and seemingly-related basePath bugs with both React-Static 5.9.12 and 6.x. I’m a huge fan of React-Static, I’ve migrated projects from other SSR libraries and it’s been a great experience overall, but unfortunately this is a showstopping blocker. I really appreciate all the work you’ve done though, using React-Static has been like a breath of fresh air!

I’d like to help out as well and I’ll take the information above as a jumping off point for my own attempts to root cause this cluster of issues. In terms of branch(es) to work against, is master the preferred branch or could it also be worthwhile to look at v5 and v7?

1reaction
tannerlinsleycommented, Feb 28, 2019

Master is up to date for v6 so use that one! Thanks for your willingness to help!

On Thu, Feb 28, 2019 at 3:32 PM Duncan notifications@github.com wrote:

@tannerlinsley https://github.com/tannerlinsley, Please reopen when you get the chance, thanks!

We’re also experiencing this issue and seemingly-related basePath bugs with both React-Static 5.9.12 and 6.x. I’m a huge fan of react-static, I’ve migrated projects from other SSR libraries and it’s been a great experience overall, but unfortunately this is a showstopping blocker. I really appreciate all the work you’ve done though, using React-Static has been like a breath of fresh air!

I’d like to help out as well and I’ll take the information above as a jumping off point for my own attempts to root cause this cluster of issues. In terms of branch(es) to work against, is master the preferred branch or could it also be worthwhile to look at v5 and v7?

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/nozzle/react-static/issues/975#issuecomment-468465800, or mute the thread https://github.com/notifications/unsubscribe-auth/AFUmCddgi0lHxlDKkwLcWM0liqQeJB_Nks5vSFkGgaJpZM4aFEZi .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Base layout does not load when accepting dynamic url
The static/ URL is resolving through your anything URL, because they don't start with an absolute path. Here's an example of a CSS...
Read more >
Dynamic basepath · Issue #595 · sveltejs/kit - GitHub
i am just trying to deploy a svelte kit app with adapter-node to mydomain.com/svelteapp and unfortunately all links are broken. is this here...
Read more >
Dynamic URLs vs. static URLs | Google Search Central Blog
It's quite hard to correctly create and maintain rewrites that change dynamic URLs to static-looking URLs. It's much safer to serve us the...
Read more >
Secret tricks for path-independent Angular apps - Symflower
Angular apps can run from arbitrary paths via two specific command line options: --base-href and --deploy-url .
Read more >
Manually constructing a Dynamic Link URL - Firebase
This link must be a well-formatted URL, be properly URL-encoded, use either HTTP or HTTPS, and cannot be another Dynamic Link.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found