Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Remove visibility: hidden from the image component (vercel#23278)
Browse files Browse the repository at this point in the history
This PR removes the `visibility` style property change from next/image. It was previously added in vercel#18195 to fix a bug that when no `src` is set, and that bug is not valid anymore as all images will always have `src` (and a fallback too).

It also fixes the problem that screen readers ignore elements with `visibility: hidden`.

Fixes vercel#23201.

## Bug

- [x] Related issues vercel#23201
- [ ] Integration tests added

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [ ] Make sure the linting passes
  • Loading branch information
shuding committed Mar 22, 2021
1 parent d81c510 commit e8bb164
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 112 deletions.
2 changes: 0 additions & 2 deletions packages/next/client/image.tsx
Expand Up @@ -295,8 +295,6 @@ export default function Image({
let sizerStyle: JSX.IntrinsicElements['div']['style'] | undefined
let sizerSvg: string | undefined
let imgStyle: ImgElementStyle | undefined = {
visibility: isVisible ? 'inherit' : 'hidden',

position: 'absolute',
top: 0,
left: 0,
Expand Down
55 changes: 0 additions & 55 deletions test/integration/image-component/base-path/test/index.test.js
Expand Up @@ -51,23 +51,6 @@ async function getComputed(browser, id, prop) {
return null
}

async function getComputedStyle(browser, id, prop) {
const val = await browser.eval(
`window.getComputedStyle(document.getElementById('${id}')).${prop}`
)
if (typeof val === 'number') {
return val
}
if (typeof val === 'string') {
const v = parseInt(val, 10)
if (isNaN(v)) {
return val
}
return v
}
return null
}

async function getSrc(browser, id) {
const src = await browser.elementById(id).getAttribute('src')
if (src) {
Expand Down Expand Up @@ -442,44 +425,6 @@ function runTests(mode) {
})
}

it('should correctly inherit the visibilty of the parent component', async () => {
let browser
try {
browser = await webdriver(appPort, '/docs/hidden-parent')

const id = 'hidden-image'

// Wait for image to load:
await check(async () => {
const result = await browser.eval(
`document.getElementById(${JSON.stringify(id)}).naturalWidth`
)

if (result < 1) {
throw new Error('Image not ready')
}

return 'result-correct'
}, /result-correct/)

await waitFor(1000)

const desiredVisibilty = await getComputed(
browser,
id,
'style.visibility'
)
expect(desiredVisibilty).toBe('inherit')

const actualVisibility = await getComputedStyle(browser, id, 'visibility')
expect(actualVisibility).toBe('hidden')
} finally {
if (browser) {
await browser.close()
}
}
})

it('should correctly ignore prose styles', async () => {
let browser
try {
Expand Down
55 changes: 0 additions & 55 deletions test/integration/image-component/default/test/index.test.js
Expand Up @@ -53,23 +53,6 @@ async function getComputed(browser, id, prop) {
return null
}

async function getComputedStyle(browser, id, prop) {
const val = await browser.eval(
`window.getComputedStyle(document.getElementById('${id}')).${prop}`
)
if (typeof val === 'number') {
return val
}
if (typeof val === 'string') {
const v = parseInt(val, 10)
if (isNaN(v)) {
return val
}
return v
}
return null
}

async function getSrc(browser, id) {
const src = await browser.elementById(id).getAttribute('src')
if (src) {
Expand Down Expand Up @@ -505,44 +488,6 @@ function runTests(mode) {
})
}

it('should correctly inherit the visibilty of the parent component', async () => {
let browser
try {
browser = await webdriver(appPort, '/hidden-parent')

const id = 'hidden-image'

// Wait for image to load:
await check(async () => {
const result = await browser.eval(
`document.getElementById(${JSON.stringify(id)}).naturalWidth`
)

if (result < 1) {
throw new Error('Image not ready')
}

return 'result-correct'
}, /result-correct/)

await waitFor(1000)

const desiredVisibilty = await getComputed(
browser,
id,
'style.visibility'
)
expect(desiredVisibilty).toBe('inherit')

const actualVisibility = await getComputedStyle(browser, id, 'visibility')
expect(actualVisibility).toBe('hidden')
} finally {
if (browser) {
await browser.close()
}
}
})

it('should correctly ignore prose styles', async () => {
let browser
try {
Expand Down

0 comments on commit e8bb164

Please sign in to comment.