-
Notifications
You must be signed in to change notification settings - Fork 93
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
Version 3 #120
Comments
That's a good idea @AleVul, thanks! That would solve the problem with native binaries needed. I'll definitely check this option out 👍 |
Sounds awesome @cyrilwanner, are you still pursuing this? I think this project is important and would love to see it flourish. I have no experience with Webpack stuff, but let me know if you need help with any laborious tasks or more general JS/TS parts of the library. |
Eagerly awaiting this! 😄 |
Remote image optimization would be amazing. 🎉 |
I'm sorry for the long silence on this issue. I just didn't have much time to work on this over the last few months, unfortunately. Currently, I'm working on compiling the different image optimization tools into WebAssembly so we are able to make the whole installation (especially in a CI/CD environment) a lot easier and more consistent. Squoosh, unfortunately, doesn't provide their compiled WASM binaries as packages, but I'm slowly getting there. |
Super cool Cyril, best of luck! 💪 |
I saw your message on the Next.js discussions board and posted a message in response to another user's questions with how I did something like this. I'd be happy to help out or give a few pointers with how I implemented something like this! |
Hi @jasonsilberman and thank you very much! But I already have a few initial questions, if you would like to give some insights. |
Hey, really looking forward to the new Version! In the meantime I had the need for an Image Component by myself so I created one and shared it here: It's still WIP but supports:
Since you wrote, you want to provide an Image Components as well, I thought it's maybe interesting for you. |
Feedback on provided component: Instead of using babel transform, we can use gatsby-image strategy. Something like this: class Lquip {
imgSrc: string;
blur: number;
}
class LquipColor {
backgroundColor: string;
}
class Trace {
imgSrc: string;
}
interface ResponsivePictureElement extends DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement> {
resources: {
sources: DetailedHTMLProps<SourceHTMLAttributes<HTMLSourceElement>, HTMLSourceElement>[]
fallbackSrc: string;
placeholder?: Lquip | LquipColor | Trace;
intrinsicWidth: number;
intrinsicHeight: number
}
}
export function Picture(props: ResponsivePictureElement) {
const { resources: { sources, fallbackSrc, placeholder, intrinsicWidth, intrinsicHeight } } = props;
let { style } = props
if (placeholder instanceof Lquip) {
// TODO can `filter` be applied to `backgroundImage` ?
style = { ...style, backgroundImage: `url('${placeholder.imgSrc}')`, filter: `blur(${placeholder.blur}px)` }
} else if (placeholder instanceof LquipColor) {
style = { ...style, backgroundColor: placeholder.backgroundColor }
} else if (placeholder instanceof Lquip) {
style = { ...style, backgroundImage: `url('${placeholder.imgSrc}')` }
}
style = { ...style, height: intrinsicHeight, width: intrinsicWidth }
return <picture {...props} style={style}>
{sources.map((r) => <source
srcSet={r.srcSet}
media={r.media}
sizes={r.sizes}
type={r.type}
{...r}
/>)}
<img src={fallbackSrc} />
</picture>
} usage <Picture resources={require('./myimage.png')} />
<Picture resources={require('./myimage.png?trace&resize&size[]=300&webp')} /> The 2 above can be equivalent with preset in the config. WDYT? |
You are right, I am processing images on upload and not on the fly. I did this because we host the images on Google Storage (with a CDN in front) and so we could not easily do resizing on the fly. Additionally, this is for a static site and we know all of the images dimensions ahead of time, so we could pre-cut all of the exact images we needed. We have deployed our image pipeline to a serverless environment, Vercel. I have not experienced any issues with using Sharp on Vercel's platform as of yet. The one thing to be consider is that you can only write to a Hope this helps. Some other thoughts on the plugin in general:
Anyway, I'm excited about the development of this plugin! |
I surprised Vercel hasn't built an image component yet. They have ones for head and link. 🤔 |
+1, a nextJS version of gatsby-image would be amazing ✨ |
Any progress on this? |
@cyrilwanner FWIW, I recently found |
@paambaati glad to hear that! I've seen that package too. And as a small update to the current state: I'm actively working on the version 3 and the first canary version is just a few days away. I'll of course post here once the canary version is published to npm. (And I've split this project into multiple modular packages, like one for the WebAssembly codecs, one for the webpack loader, one for the components and this which binds all together, so it could basically also be used outside of a next.js project. That's the reason why you don't see much going in in this repository. The other repositories will of course also made public when they are ready, but they are currently lacking a bit of documentation) |
It was a lot of work and there is still a lot to do, but the first canary version is now available 🎉 Not all planned features are already available. The remote image optimization & lazy loading components (like blur-up) are missing. But they are still planned and will get added soon to the canary version. Some of the new features are:
I suggest you check out the readme on the canary branch for more details. Any feedback, further ideas, or bug reports are of course very much appreciated and will help to bring the canary version to the @latest tag faster. The babel plugin for the image components probably doesn't recognize 100% of all use-cases, so if you find any, please share them if possible. I would be very happy if some of you could test the canary version and report back if something is not working. Or if some of you have open-source projects using this package, it would already help if you can share them with me so I can see if there are some use-cases I did not think about and try it myself to update next-optimized-images to the canary version. Also, if you find anything unclear in the readme or upgrade guide, don't hesitate to ask. It was already late when I wrote there so it is possible that not everything is 100% is explained well enough. If you want to update this plugin in an existing project, please read the upgrading guide guide as some breaking changes were introduced. Also, not yet all features previously available are already in the canary version. If your project depends on one of the following features, you may have to wait a few more days until they were ported into the new version:
And thank you all for your continued support and feedback. I understand that it took a long time to get to this point, but I'm very happy with the result and think that it was worth it. And the remaining todos won't take that long anymore. |
Great work @cyrilwanner, I've given v3 a test and will look out for issues and reference them here. Might be a better way to track the v3 issues though. #164 (having trouble building). |
The babel plugin does not currently recognize styled components like the one below: import styled from '@emotion/styled';
S.Image = styled(Img)({
width: '100%'
}); |
Thank you for already testing it!
Yes I agree, that may be the better way to track issues 👍
That is something I completely forgot about as I'm not using that in my projects. Perfect that you could test that, thank you. I'll of course add support for styled components. |
I have a bug in component =( if I use Img component in div with onClick={...} |
@cyrilwanner 👋 Just checking in, and I wanted to bring to your notice the impending release of Webpack 5. As |
I also have the warnings for the max listeners. Unfortunately setting maxListener to any number doesn't solve my issue. I have no problem on my local machine. The issues comes when I try to deploy on Vercel :
|
@cyrilwanner Just tried out canary with Next v10 and it works great for me! Awesome work! |
Same issue as @DonovanCharpin |
@cyrilwanner I'm not sure if you've addressed this elsewhere, but what's the main difference between this project and the new Next.js built-in image optimization? |
@nicholaschiang I am going to try to explain, hopefully @cyrilwanner can be more thorough. Next.js built-in image optimization works only with an API ( as in serverless ) and the images are not generated in build time, this also means outside of Vercel you cant use them ( for now ). This package optimizes the images in build time so you have them ready to use post-build. |
Yup, I figured as much but was wondering if there were any other differences. Right now, this package is great for build-time optimization (e.g. when you have a fixed number of static images) but can't easily be used with user-uploaded images. I noticed in this RFC that you're thinking of adding runtime optimization features and was wondering why (because Next.js 10 already has them built-in). |
I have the same issue with the Vercel Deployment. @meienberger Have you found any workaround/solution in the meantime? |
@maxwolfs I could not find a solution and I moved to a server based solution. Maybe you can try with Next v10 if you are not already there |
I ran into the same error that @meienberger had. I was able to get past it (not solve) by:
Note: I only have 20 or so images I know that this "solution" isn't great but it enabled me to build my Next.js app once again. FYI it also successfully built on Vercel. Using: "next": "latest",
"next-optimized-images": "^3.0.0-canary.10", |
@enpclark With a |
I just tried this out and it's mostly pretty good! But I'm wondering why the use of My understanding is that |
Is this V3 still happening? I haven't seen any comments from @cyrilwanner since Aug 12th 2020. No commit have been made since Aug 9th 2020. I hope it's not been cancelled because NextJs launched their own image optimization solution. NextJs solution is far from perfect and has plenty of troubles:
As you can see, we do need an alternative because NextJs solution isn't rosy as soon as you dig a little deeper. |
I second @TheThirdRace’s thoughts on the new built-in Next.js solution and would very much like to continue using next-optimized-images v3. I appreciate @cyrilwanner may have moved onto other priorities—that’s the nature of open source some times, and I thank him for his efforts thus far. It would be good to hear whether or not this library is likely to see any further development though so we can make alternative arrangements. |
Thanks for bringing this up, I was wondering the same thing. I don't currently have (and I don't want to have) node at all in production, so I can't use the Next.js solution. Is anybody using this canary version? Is it ready for release or does it still have open issues? |
Mayby @cyrilwanner should update the module status... |
@FreedomBen I'm using it on a small project and it seems stable enough but I too am concerned there's no development here anymore. Maybe a fork would be good if someone is interested to maintain. |
Is this still happening @cyrilwanner? Your feedback here would really appreciated. |
So this library is dead? |
Let us know if you are looking for maintainers @cyrilwanner. Im sure there are people who are happy to help! |
I'm also eagerly awaiting V3 Also I love the fact that with each deploy the image is placed in cache with a new hashed file name, so each deploy I get fresh images I don't have to wait for the cache to expire for users to see new version of the same image file. Also I'm not using Vercel to deploy I've got my own AWS CDK configuration so I have no idea if the Next image caching strategies are even going to work with me and my AWS CDK deployment at run time. |
I think I saw on twitter that he's busy with his thesis or something. Eventually priorities will shift after that and all the nice tools he made will flourish again :) |
It's perfectly ok to be busy, very understandable and we can all relate to that. It would be nice if he could take 10 minutes and put a big message at the top of the Readme file on the repo so people stop asking the same question 😅 |
@cyrilwanner any progress can i use in production? |
Great job so far on the canary and the library is very much appreciated. The only bug I found is that inlining svg and converting them to webp causes the base64 encoded svg to be included instead of the webp one
|
It seems like this project is dead anyways, but I thought I'd ask ... given that Next itself has switched from Babel to Rust, is making Babel a requirement of v3 wise? |
Background
This project started out as a small package. Over time, more and more features were added and it now provides many different things and is used by many developers. But I'm not 100% happy with the current version for the following reasons:
Idea
To make this package robust for the future and easy to maintain, I think the only way is to fix those issues. And this probably requires a rewrite of the whole package.
It can be broken down into multiple parts:
Webpack loaders
This is the most important part of this package and is currently out of our control. To support use-cases such as mentioned in #84 or #91 and so we are able to provide a stable plugin, I think the only way is to write an own webpack loader which does the image optimizations. That would have the following advantages:
Next.js plugin
This plugin would configure the independent webpack loader for easy use with next.js. It should also support the upcoming next.js plugin system for an easy installation.
Support run-time optimization
One of the most requested features was to be able to optimize images during run-time (e.g. from an API) and not only local images during build-time (see #104, #77, #74). With the API routes introduced in next.js 9, I think it should be possible to provide an easy-to-use service for that. It obviously can't relay on webpack, but the code used in the webpack loader should be reusable.
That would have the following advantages:
But this feature would need to be defined more detailed (e.g. it would need a store, like S3, so images are not optimized on every request, and this API would be best located behind a CDN, etc.).
Provide image components
Creating an image component is not easy, especially if you want to support all features of this plugin (webp fallback, lqip, srcset, ...). And you still have to think about what happens when JS is disabled (while lazy loading), how it has to be optimized for screen readers and search engines and so on. So if you want your images to be working well for everyone, it is not just
<img src={require('./image.jpg')} />
, there is a lot more work to do and you don't want to do this again in every project.So I'm thinking about providing an image component that will work well with this plugin and already does most of the things for you (non-JS fallback, a11y, lazy loading with fallbacks, ...).
It should support the following things:
Additionally, it would be nice to provide a babel plugin which makes it even easier to use this component.
So instead of this:
You would only use it like this and the babel plugin will transform it to the way more complex way above:
Feedback wanted
I am of course open to any feedback on any part of this idea. Also, if you have ideas of new features, now would be the time as they could be included from the beginning of the new version.
I am not quite sure on which image optimization library this should be based on. Right now, it is mainly imagemin but I am not really happy with it since it is not easy to install, especially in some CI/CD environments since it requires specific binaries to be installed on the system.
So I was thinking about using sharp as the main optimization library as it is a lot easier to install, has a great node API and is still quite fast compared to other node libraries.
Feedback on this would be very appreciated, especially:
Is there an ETA?
No, development has started but is in the early stages. The features mentioned above are quite complex and require a lot of work, so it will probably take some weeks. But I will update this issue when progress is made and when a canary version is available.
The text was updated successfully, but these errors were encountered: