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

Bug: Error displaying images in posts #827

Open
vi8pro opened this issue Jan 19, 2024 · 4 comments
Open

Bug: Error displaying images in posts #827

vi8pro opened this issue Jan 19, 2024 · 4 comments

Comments

@vi8pro
Copy link

vi8pro commented Jan 19, 2024

Visit the homepage, click on any article containing an image. The image in the article will not display, you will have to refresh the article to display the image. I use Chrome on iphone 12 promax.
IMG_3615

@QuantGeekDev
Copy link

I think it's due to the client-side routing. The same happens with gifs - which I addressed in my media optimizatoin pull request #826 but it still happens with images embedded through markdown

@hungvu946
Copy link

hungvu946 commented Jan 22, 2024

Let's go to overreacted.io, turn on debugger (F12 chrome > Network), and click post Algebraic Effects for the Rest of Us
And observing through the debugger, every time the page is loaded it will load 2 images:

  1. https://overreacted.io/effects.jpg - 404
  2. https://overreacted.io/algebraic-effects-for-the-rest-of-us/effects.jpg

I can't find why it loads the first url resulting in a 404 error. Any ideas?
Screenshot_4

@hungvu946
Copy link

hungvu946 commented Jan 22, 2024

I have found the solution. Need to handle adding the article slug to the img's src
in page.js, add img to MDXRemote:

img: (props) => {
	if (props.src) {
	  props.src = `/${params.slug}/${props.src}`;
	}

	return <img {...props} />;
},

@QuantGeekDev
Copy link

@hungvu946
Smart, are you going to PR it or should I add it?

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

No branches or pull requests

3 participants