-
Notifications
You must be signed in to change notification settings - Fork 29.4k
fix(next/image): don't call ReactDOM.preload if missing, such as jest #53443
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a7c1060
fix(image): don't call ReactDOM.preload if missing
balazsorban44 0425a27
Apply suggestions from code review
styfle e09b6f9
Merge branch 'canary' into fix/image-preload-jest
styfle 17ce20c
fix typo
styfle 38ef1dc
update test
styfle d8c05ff
fix test
styfle c2775ef
add missing layout
styfle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
test/production/jest/next-image-preload/app/app/layout.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react' | ||
export default function RootLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode | ||
}) { | ||
return ( | ||
<html lang="en"> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import React from 'react' | ||
import Image from 'next/image' | ||
import logo from './next.svg' | ||
|
||
export default function MyImage() { | ||
return <Image alt="" src={logo} priority /> | ||
} |
16 changes: 16 additions & 0 deletions
16
test/production/jest/next-image-preload/app/jest.config.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const nextJest = require('next/jest') | ||
|
||
const createJestConfig = nextJest({ | ||
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment | ||
dir: './', | ||
}) | ||
|
||
// Add any custom config to be passed to Jest | ||
const customJestConfig = { | ||
// if using TypeScript with a baseUrl set to the root directory then you need the below for alias' to work | ||
moduleDirectories: ['node_modules', '<rootDir>/'], | ||
testEnvironment: 'jest-environment-jsdom', | ||
} | ||
|
||
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async | ||
module.exports = createJestConfig(customJestConfig) |
50 changes: 50 additions & 0 deletions
50
test/production/jest/next-image-preload/next-image-preload.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { createNext, FileRef } from 'e2e-utils' | ||
import { NextInstance } from 'test/lib/next-modes/base' | ||
import path from 'path' | ||
import execa from 'execa' | ||
|
||
const appDir = path.join(__dirname, 'app') | ||
|
||
describe('next/jest', () => { | ||
let next: NextInstance | ||
|
||
beforeAll(async () => { | ||
next = await createNext({ | ||
skipStart: true, | ||
files: { | ||
app: new FileRef(path.join(appDir, 'app')), | ||
styfle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[`tests/index.test.tsx`]: ` | ||
import { render, screen } from '@testing-library/react' | ||
import Page from '../app/page' | ||
|
||
it('<Page /> renders', () => { | ||
render(<Page />) | ||
const logo = screen.getByRole('img') | ||
expect(logo).toBeDefined() | ||
}) | ||
`, | ||
'jest.config.js': new FileRef(path.join(appDir, 'jest.config.js')), | ||
}, | ||
dependencies: { | ||
jest: '29.6.2', | ||
'jest-environment-jsdom': '29.6.2', | ||
'@testing-library/react': '14.0.0', | ||
'@testing-library/jest-dom': '5.17.0', | ||
}, | ||
}) | ||
}) | ||
afterAll(() => next.destroy()) | ||
|
||
it('Should not throw preload is undefined error', async () => { | ||
const { stdout, stderr } = await execa( | ||
'pnpm', | ||
['jest', 'tests/index.test.tsx'], | ||
{ | ||
cwd: next.testDir, | ||
reject: false, | ||
} | ||
) | ||
// Uncaught [TypeError: (0 , _reactdom.preload) is not a function] | ||
expect(stdout + stderr).not.toContain('is not a function') | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.