score:3
How I understand the problem
The image html is correctly inserted into the page
gatsby-image
loads the lowest quality image and applies some inline styles. All that information is present in the html) This is done to enable the blur-up effect on the image for a better UX.The client side code that would load a higher resolution image and remove the inline styles is never applied.
Useful diagnostic information
- The function inside
useEffect
does not get run on the server-side, but rather on the client after the component has mounted. It's possible to verify this by adding aconsole.log
statement inside the effect and seeing that it is logged on the browser's console.
Source of the problem
ReactDOMServer.renderToString()
only builds the HTML that's required by a component, it then requires the component to be hydrated.
Direct fix
- You can use
ReactDOM.render
to put the image on the page, given that the effect will execute client side. I have a PR showing that here.
Recommended approach
- You could instead import the image inside the mdx component and directly render it there. Your gatsby config can already support this 👍 In
content/blog/hello-world/index.mdx
, you can replace theinjectImage
div with this
(where the text inside the[]
is the alt text) - This documentation might be helpful
Hope that helps! 😄
score:0
I have faced this problem before with my first Gatsby project. The problem similar to this chat and the error image issue here.
If you replace GatsbyImageSharpFixed_withWebp_tracedSVG
like they talked in spectrum chat above, or this is my current code for example, basically is related to WebP
new image format.
export const query = graphql`
query {
allImageSharp {
edges {
node {
fluid(maxWidth: 110) {
aspectRatio
originalName
sizes
src
srcSet
srcWebp
tracedSVG
}
}
}
}
}
`;
Hope this help.
score:0
I think the problem could be in the useEffect
const componentCreatedFromMarkdown = ({data}) => {
...
useEffect(() => {
const injectDivs = Array.from(document.getElementsByClassName('injectDivs'))
injectDivs.forEach((aDiv) => {
aDiv.innerHTML = ReactDOMServer.renderToString(<MyComponent args={myArgs} />)
}
},[])
...
}
I think you should try to add useEffect(()=>{},[]), the second argument to refresh the image only when the component is mounted, without this the image will be refreshed each time.
Source: stackoverflow.com
Related Query
- Injecting gatsby-image into html created from markdown using ReactDOMServer.renderToString
- Gatsby + Markdown: How to get data from a specific markdown file into a single page?
- Saving HTML markup from Rich Text Editor into MongoDB using React.js
- Convert Markdown to HTML from within a Rich-Text Component with Gatsby
- Injecting HTML code into Gatsby MD file for display
- Pass PageProps from Gatsby and Parent into Functional Component returns undefined using React and TS
- Gatsby Unable to process image from markdown files
- Using styles from scss or css into Gatsby doesn't work
- Stuck trying to fetch data from MongoDB into Gatsby using `gatsby-source-mongodb`
- Replacing ":customimage:" from string into image but returns [object Object] in HTML view in React.js
- How to properly fit an image into a div in HTML and CSS using ReactJS
- How Can I Render an Image From JSON Data Into A Table Row Using React?
- Modifying data from graphql queries into react components using gatsbyjs works in gatsby develop but breaks in gatsby build
- How to show image in react using the data from mysql created by xampp
- Is there a right way to pass data into a React component from the HTML page?
- generating pdf from Html in React using html2canvas and jspdf
- How to prevent Gatsby image from blurring a logo with every reload?
- How to upload image using ReactJS and save into local storage?
- How to paste image into CKEditor5 in React using Base64UploadAdapter
- Detect broken image when using hydrate instead of render from react-dom
- Fetch image from S3 Bucket using React JS
- Cloudinary image upload from React: am including Cloudinary unsigned preset but get "Upload preset must be specified when using unsigned upload"
- How to get image from public folder without using Webpack
- Loading Sass and injecting CSS text into a parent document from a React app
- React not turning HTML string from JSON into text
- Using React-Hooks, how do I prevent a component created from Array.map from re-rendering if one of it's siblings changes state?
- upload an image with a token to a fastAPI route using POST from reactJS
- Gatsby graphql query for GatsbyImage to use a local image from project
- How to display image from AWS s3 using spring boot and react?
- How to display data from JSON into html table
More Query from same tag
- how do I interpolate a Link component in Next-i18next / React i18next that changes position in the text
- Forwarding refs through multiple components
- React.js render json response, co fetch or axios
- Cannot change value of select element using enzyme
- Error in posting JSON form data to REST api using AJAX in React
- How to add a border to an image inside an SVG circle
- How to render another component on submitting a form
- applyMiddleware() ignored? redux-thunk never fires callback, redux-logger won't log, everything done right
- How can we call onNewRequest property in onBlur in AutoComplete Material-UI?
- ReactJs: Parent or child component responsible for processing data to render view?
- How to change individual cart quantity in React?
- Get data of array containing array in reactjs
- Wait for all recursive api calls to finish and process the result
- Material-UI injectFirst doesn't work with storybook
- React: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL
- How do I create a cookie after a response from the server? react
- passing just the index clicked to the prop
- How do Inherit from custom React Component without losing flow type information?
- React - Unhandled Rejection (TypeError): e.preventDefault is not a function
- Error Could not resolve dependency: redux-react-session
- How to dynamically show or hide form fields depending on the state of a BooleanInput field in react-admin?
- How to delete a list item in React Functional Component without using id
- Restarting setInterval after clearInterval in React
- ReactJS: Get multiple checkboxes value with material-ui
- Vanilla CSS in React?
- why i am not able to get map() method index inside of Click handler function in reactjs
- React App's Imported Object Doesn't Update Automatically On Page
- How can I select image in Semantic-UI-React Dropdown menu?
- react-hook-form can't correctly validation with value and onChange after submit
- Trying to call useContext outside of a function component