Skip to content

Commit a82287d

Browse files
authored
[Frontend] Global img provider (#1571)
* Add a global image loader * update next to 13.0.0 * remove px from width/hegihts nubmers * bump versions * bump versions * bump versions * remove unecessary spaces * fix distorted iamge, add some extra memory for stability * add changelog * fix checks
1 parent f909932 commit a82287d

14 files changed

+292
-309
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ the release.
3737
([#1556](https://github.com/open-telemetry/opentelemetry-demo/pull/1556))
3838
* [frontend] Slowloading of images based on imageSlowLoad flag
3939
([#1515](https://github.com/open-telemetry/opentelemetry-demo/pull/1486))
40+
* [frontend] Fix imageloading issues on optimized images. bump next.js version
41+
([#1571](https://github.com/open-telemetry/opentelemetry-demo/pull/1571))
4042

4143
## 1.9.0
4244

docker-compose.minimal.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ services:
188188
deploy:
189189
resources:
190190
limits:
191-
memory: 200M
191+
memory: 250M
192192
restart: unless-stopped
193193
ports:
194194
- "${FRONTEND_PORT}"

docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ services:
257257
deploy:
258258
resources:
259259
limits:
260-
memory: 200M
260+
memory: 250M
261261
restart: unless-stopped
262262
ports:
263263
- "${FRONTEND_PORT}"

src/frontend/components/CartDropdown/CartDropdown.styled.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ export const Item = styled.div`
5656
`;
5757

5858
export const ItemImage = styled(Image).attrs({
59-
width: '80px',
60-
height: '80px',
59+
width: '80',
60+
height: '80',
6161
})`
6262
border-radius: 5px;
6363
`;

src/frontend/components/CartIcon/CartIcon.styled.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ export const CartIcon = styled.a`
1616
`;
1717

1818
export const Icon = styled(Image).attrs({
19-
width: '24px',
20-
height: '24px',
19+
width: '24',
20+
height: '24',
2121
})`
2222
margin-bottom: 3px;
2323
`;

src/frontend/components/CheckoutItem/CheckoutItem.styled.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ export const Status = styled.div`
7979
`;
8080

8181
export const ItemImage = styled(Image).attrs({
82-
width: '80px',
83-
height: '80px',
82+
width: '80',
83+
height: '80',
8484
})`
8585
border-radius: 5px;
8686
`;

src/frontend/components/CheckoutItem/CheckoutItem.tsx

+1-25
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,6 @@ interface IProps {
1414
address: Address;
1515
}
1616

17-
interface ImageLoaderProps {
18-
src: string;
19-
width: number;
20-
quality?: number;
21-
}
22-
/**
23-
* We connect to imageprovider through the envoy proxy, straight from the browser, for this we need to know the current hostname and port.
24-
* During building and serverside rendering, these are undefined so we use some conditionals and default values.
25-
*/
26-
let hostname = "";
27-
let port = 80;
28-
let protocol = "http";
29-
30-
if (typeof window !== "undefined" && window.location) {
31-
hostname = window.location.hostname;
32-
port = window.location.port ? parseInt(window.location.port, 10) : (window.location.protocol === "https:" ? 443 : 80);
33-
protocol = window.location.protocol.slice(0, -1); // Remove trailing ':'
34-
}
35-
const imageLoader = ({ src, width, quality }: ImageLoaderProps): string => {
36-
// We pass down the optimization request to the iamgeprovider service here, without this, nextJs would trz to use internal optimizer which is not working with the external imageprovider.
37-
return `${protocol}://${hostname}:${port}/${src}?w=${width}&q=${quality || 75}`;
38-
}
39-
40-
4117
const CheckoutItem = ({
4218
checkoutItem: {
4319
item: {
@@ -53,7 +29,7 @@ const CheckoutItem = ({
5329
return (
5430
<S.CheckoutItem data-cy={CypressFields.CheckoutItem}>
5531
<S.ItemDetails>
56-
<S.ItemImage src={"/images/products/" + picture} alt={name} loader={imageLoader}/>
32+
<S.ItemImage src={"/images/products/" + picture} alt={name}/>
5733
<S.Details>
5834
<S.ItemName>{name}</S.ItemName>
5935
<p>Quantity: {quantity}</p>

src/frontend/components/Header/Header.styled.ts

-4
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@ export const NavBarBrand = styled(Link)`
4040
display: flex;
4141
align-items: center;
4242
padding: 0;
43-
44-
img {
45-
height: 30px;
46-
}
4743
`;
4844

4945
export const BrandImg = styled.img.attrs({

src/frontend/components/Header/Header.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const Header = () => {
1111
<S.NavBar>
1212
<S.Container>
1313
<S.NavBarBrand href="/">
14-
<a><S.BrandImg /></a>
14+
<S.BrandImg />
1515
</S.NavBarBrand>
1616
<S.Controls>
1717
<CurrencySwitcher />

src/frontend/next.config.js

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ const nextConfig = {
5757
NEXT_PUBLIC_OTEL_SERVICE_NAME: OTEL_SERVICE_NAME,
5858
NEXT_PUBLIC_OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: PUBLIC_OTEL_EXPORTER_OTLP_TRACES_ENDPOINT,
5959
},
60+
images: {
61+
loader: "custom",
62+
loaderFile: "./utils/imageLoader.js"
63+
}
6064
};
6165

6266
module.exports = nextConfig;

0 commit comments

Comments
 (0)