Coder Social home page Coder Social logo

Comments (5)

Niels-IO avatar Niels-IO commented on June 27, 2024 3

Hi @NicolasRoehm,

The noscript tags should work properly now. Check out version 0.15.0 🙂

from next-image-export-optimizer.

Niels-IO avatar Niels-IO commented on June 27, 2024

Hi @NicolasRoehm,

Thanks for the bug report. I looked, and I know at least why this noscript img tag is not being generated.

This is how the export is taking place. I need to use the dynamic function with SSR off as there is a hydration error otherwise. When I would export the ExportedImage component directly, the noscript img tag would be generated but the hydration error occurs.

const DynamicExportedImage = dynamic(() => Promise.resolve(ExportedImage), {
  ssr: false,
});

export default function (props: ExportedImageProps) {
  const isStaticImage = typeof props.src === "object";
  const width = (isStaticImage && props.width) || (props.src as any).width;
  const height = (isStaticImage && props.height) || (props.src as any).height;

  return isStaticImage ? (
    <div style={isStaticImage ? { aspectRatio: width / height } : {}}>
      <DynamicExportedImage {...props} />
    </div>
  ) : (
    <DynamicExportedImage {...props} />
  );
}

I have to find a workaround for the hydration error. I think it happs because the environment variables are not accessible on the server side inside an imported module like the ExportedImage component.

from next-image-export-optimizer.

NicolasRoehm avatar NicolasRoehm commented on June 27, 2024

Hi @Niels-IO,
I've been playing with React & Next for only 2 weeks, so I'm not able to help much here.
Do you think something like this might help bypass the ssr:false vercel/next.js#35773 (comment) ?

from next-image-export-optimizer.

Niels-IO avatar Niels-IO commented on June 27, 2024

Hi @NicolasRoehm,

I played around, but I cannot get around one issue: The ExportedImage component is a compiled commonjs file, and for the first server render, the process.env is undefined. One solution would be that I can export the ExportedImage component as an ES module and let Next.js compile the source. Unfortunately, I have had no luck in getting this to work for now.

from next-image-export-optimizer.

NicolasRoehm avatar NicolasRoehm commented on June 27, 2024

Using something like https://github.com/martpie/next-transpile-modules ?
About environment variables, I see a lot of NextJs plugins uses their own module.exports = {} in a dedicated config file instead of the next.config.js. I don't know if it can help 😅

from next-image-export-optimizer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.