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

Make the Image component AMP-aware #826

Merged
merged 22 commits into from
May 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f0ade07
Image: Remove the Intersection observer fallback and make AMP-aware
michalczaplinski May 21, 2021
b50eb77
Image: Fix types and imports
michalczaplinski May 21, 2021
44c6817
Image: Update the tests
michalczaplinski May 21, 2021
2f98842
Image: Add changeset
michalczaplinski May 22, 2021
34a31b8
Image: Mess around with the Image implementation
michalczaplinski May 25, 2021
2c97377
Image: Add the injectProps and fix implementation
michalczaplinski May 25, 2021
33f89a1
Image: Add additional props and fix the amp `layout` attribute
michalczaplinski May 25, 2021
327b104
AMP Image: Remove unnecessary frontity.state
michalczaplinski May 25, 2021
a5239ac
Infra: Remove --coverage flag from npm scripts
michalczaplinski May 22, 2021
816e893
Infra: Remove `collectCoverageFrom` from jest config
michalczaplinski May 22, 2021
5980c20
Add --ci flag to the cli-e2e tests
michalczaplinski May 22, 2021
c8f65cb
Version Packages
github-actions[bot] May 25, 2021
021bb90
Transpile packages that contain webpack in the name
luisherranz May 25, 2021
91cc4d8
Add changeset
luisherranz May 25, 2021
4bf469d
Update webpack snapshots
luisherranz May 25, 2021
c44e970
Image: Update comments
michalczaplinski May 25, 2021
5df1b99
Version Packages
github-actions[bot] May 26, 2021
a4fe52d
Merge branch 'dev' into amp-aware-image
michalczaplinski May 27, 2021
6fcf9c4
Revert "Image: Fix types and imports"
michalczaplinski May 27, 2021
7b489a5
Rename Props to ImageProps
michalczaplinski May 27, 2021
82ad7c1
Image: Remove `Connect` type
michalczaplinski May 28, 2021
5d41a34
Merge branch 'dev' into amp-aware-image
michalczaplinski May 28, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/big-beds-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@frontity/components": minor
---

Make the Image component from `@frontity/components` AMP-aware and remove the Intersection Observer fallback which used to lazily load images in the absence of native lazy loading.
68 changes: 8 additions & 60 deletions e2e/integration/frontity-01/image.spec.js
Original file line number Diff line number Diff line change
@@ -1,75 +1,23 @@
import expect from "expect";

describe("Image lazy-loading (with Intersection Observer)", () => {
describe("Image lazy-loading (with native lazy-load)", () => {
beforeEach(() => {
cy.viewport(360, 640);
cy.visit("http://localhost:3001?frontity_name=image", {
onBeforeLoad(win) {
// Remove the "loading" prop from the HTMLImageElement prototype
Object.defineProperty(win.HTMLImageElement.prototype, "loading", {
configurable: true,
writable: true,
});
// win.HTMLImageElement.prototype.loading = undefined;
delete win.HTMLImageElement.prototype.loading;
},
});
});

it("native lazy load should not exist", () => {
return cy
.window()
.its("HTMLImageElement")
.then((htmlImageElement) => {
expect("loading" in htmlImageElement.prototype).toBe(false);
});
});

it("should work scrolling from top to bottom", () => {
cy.scrollTo("topLeft");
cy.get("img:not(.top.left)").should("not.be.visible");
cy.get("img.bottom.left")
.scrollIntoView({ duration: 300 })
.should("be.visible");
cy.get("img.right").should("not.be.visible");
});

it("should work scrolling from bottom to top", () => {
cy.scrollTo("bottomLeft");
cy.get("img:not(.bottom.left)").should("not.be.visible");
cy.get("img.top.left")
.scrollIntoView({ duration: 300 })
.should("be.visible");
cy.get("img.right").should("not.be.visible");
cy.visit("http://localhost:3001?frontity_name=image");
});

it("should work scrolling from left to right", () => {
it("should render an image with loading=lazy", () => {
cy.scrollTo("topLeft");
cy.get("img:not(.bottom.left)").should("not.be.visible");
cy.get("img.top.right")
.scrollIntoView({ duration: 300 })
.should("be.visible");
cy.get("img.bottom").should("not.be.visible");
cy.get("img[height]").should("have.attr", "loading", "lazy");
});
});

describe("Image lazy-loading (with native lazy-load)", () => {
describe("amp-image", () => {
beforeEach(() => {
cy.viewport(360, 640);
cy.visit("http://localhost:3001?frontity_name=image");
cy.visit("http://localhost:3001/amp-image/?frontity_name=amp-image");
});

it("should render an image without loading if it doesn't have height", () => {
it("should render an amp-image", () => {
cy.scrollTo("topLeft");
cy.get("img:not([height])").should("not.have.attr", "loading");
cy.get("img:not([height])").should("not.be.visible");
cy.get("img:not([height])")
.scrollIntoView({ duration: 300 })
.should("be.visible");
});

it("should render an image with loading=lazy if it has a height", () => {
cy.scrollTo("topLeft");
cy.get("img[height]").should("have.attr", "loading", "lazy");
cy.get("amp-img[height]").should("have.attr", "layout", "fill");
});
});
5 changes: 5 additions & 0 deletions e2e/project/frontity.settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ const settings: Settings<
name: "image",
packages: ["e2e-image"],
},
{
name: "amp-image",
mode: "amp",
packages: ["@frontity/amp", "e2e-image"],
},
{
name: "fonts",
packages: [
Expand Down
172 changes: 0 additions & 172 deletions packages/components/__tests__/__snapshots__/image.jsdom.tests.tsx.snap

This file was deleted.

115 changes: 0 additions & 115 deletions packages/components/__tests__/__snapshots__/image.node.tests.tsx.snap

This file was deleted.