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

Node version support and lazy loading changes #4

Merged
merged 7 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/app-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"preinstall": "cd ../../ && npm install && npm run build && npm pack && cd example/app-router && npm install ../../imagekitio-next-1.0.0.tgz"
"preinstall": "cd ../../ && npm install && npm run build && npm pack && cd example/app-router && npm install ../../imagekitio-next-1.0.1.tgz"
},
"dependencies": {
"dotenv": "^16.4.5",
Expand Down
2 changes: 1 addition & 1 deletion example/page-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"build": "next build",
"start": "next start",
"lint": "next lint",
"preinstall": "cd ../../ && npm install && npm run build && npm pack && cd example/page-router && npm install ../../imagekitio-next-1.0.0.tgz"
"preinstall": "cd ../../ && npm install && npm run build && npm pack && cd example/page-router && npm install ../../imagekitio-next-1.0.1.tgz"
},
"dependencies": {
"dotenv": "^16.4.5",
Expand Down
136 changes: 68 additions & 68 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "imagekitio-next",
"version": "1.0.0",
"version": "1.0.1",
"description": "Next.js SDK for ImageKit.io which implements client-side upload and URL generation for use inside a next application.",
"scripts": {
"build:js": "rollup -c",
Expand All @@ -9,7 +9,7 @@
"type-check:watch": "npm run type-check -- --watch",
"build": "rm -rf dist*; npm run build:types && npm run build:js",
"test:e2e": "cypress open",
"serve:app-router": "cd example/app-router && next dev"
"serve:app-router": "cd example/app-router && npm run dev"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -52,7 +52,7 @@
"imagekit-javascript": "^3.0.2"
},
"engines": {
"node": ">=18.17.0"
"node": ">=12"
},
"peerDependencies": {
"next": "^12 || ^13 || ^14",
ahnv marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
14 changes: 8 additions & 6 deletions src/components/IKImage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const IKImage = (props: Omit<ImageProps, "src" | "loading" | "loader"> & IKImage
const { loading } = props;

if (initialized) {
if (window && "IntersectionObserver" in window && loading === "lazy") {
if (window && "IntersectionObserver" in window && loading === "lazy" && lqip) {
const connectionType = fetchEffectiveConnection();
let rootMargin = "1250px";
if (connectionType !== "4g") rootMargin = "2500px";
Expand Down Expand Up @@ -138,25 +138,27 @@ const IKImage = (props: Omit<ImageProps, "src" | "loading" | "loader"> & IKImage
useEffect(() => {
// if height and width are there in transformation skip props height and width and add fill =true
const updatedRestProps = restProps;
if (
transformation?.length &&
transformation.some((obj) => obj.hasOwnProperty('height') || obj.hasOwnProperty('width'))
) {
if (transformation?.length && transformation.some((obj) => obj.hasOwnProperty("height") || obj.hasOwnProperty("width"))) {
if (updatedRestProps.height) delete updatedRestProps["height"];
if (updatedRestProps.width) delete updatedRestProps["width"];
updatedRestProps["fill"] = true;
}
setImageProps(updatedRestProps);
}, []);

useEffect(()=>{
if(lqip?.active)
console.warn("In [imagekitio-next], loading is set to eager when LQIP is used.")
},[lqip])

return currentUrl != undefined && Object.keys(imageProps).length ? (
<NextImage
loader={({ src }) => src}
alt={alt}
src={currentUrl ? currentUrl : ""}
ref={imageRef}
unoptimized
loading="eager"
loading={lqip?.active ? "eager" : loading}
{...imageProps}
/>
) : (
Expand Down
Loading
Loading