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

Possible Img Require() problem? #87

Closed
Axion741 opened this issue Jan 7, 2019 · 4 comments
Closed

Possible Img Require() problem? #87

Axion741 opened this issue Jan 7, 2019 · 4 comments
Labels
question Further information is requested

Comments

@Axion741
Copy link

Axion741 commented Jan 7, 2019

I'm trying to narrow down why my images are breaking when parsed.

The HTML string to be parsed is this;
<img src={require("./img/articles/2019/1/react.png")}></img>

Which is then parsed into this;
<img src="{require("./img/articles/2019/1/react.png")}">
Resulting in a broken Image.

For testing I hardcoded an Image in below with this;
<img src={require("./img/articles/2019/1/react.png")}/>
And it loads just fine.

Any thoughts?

@remarkablemark
Copy link
Owner

Hi @Axion741, are you properly using template literals (template strings) here?

// regular string
'<img src={require("./img/articles/2019/1/react.png")}></img>';

// template string
`<img src="${require("./img/articles/2019/1/react.png")}">`

The regular string will stringify the require statement whereas the string template will interpolate the require value.

Also, like you shown in your last example, the img tag is a void element so it should be self-closing:

// good
<img src="file.png">
<img src="file.png" />

// bad
<img src="file.png"></img>

If I'm misunderstanding your issue, could you please reproduce it in a CodeSandbox?

@remarkablemark remarkablemark added the question Further information is requested label Jan 8, 2019
@Axion741
Copy link
Author

Axion741 commented Jan 8, 2019

Well now I'm at even more of a loss.
With the fixed template strings, my HTML parses perfectly in the sandbox, but the image is still broken for me in my app.
The rest of the HTML pops out fine, but the Img tag still parses to this;
<img src="${require('./img/articles/2019/1/react.png')}">
Instead of interpolating the require.

@remarkablemark
Copy link
Owner

Sorry for missing your last comment @Axion741. Were you able to resolve your issue?

@remarkablemark
Copy link
Owner

Closing issue due to inactivity. Feel free to reopen if there are any new updates.

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

No branches or pull requests

2 participants