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

fix: correctly pass resolvedBaseUrl for Next.js 13.2.0+ #26399

Merged
merged 10 commits into from
Apr 6, 2023

Conversation

lmiller1990
Copy link
Contributor

Additional details

As of v13.1.7-canary.7, Next.js projects setting baseUrl to anything other than the default "." would not correctly resolve modules.

Diff: vercel/next.js@v13.1.7-canary.6...v13.1.7-canary.7. Lots of files but mostly static content. Here's the exact line that broke us.

getBaseWebpackConfig(this.dir, {
  ...commonWebpackOptions,
  compilerType: COMPILER_NAMES.client,
  entrypoints: entrypoints.client,
  ...info // <====== new in 13.2.0
})

info contains info.resolvedBaseUrl, which we are currently not passing. I updated our nextHandler to include the resolvedBaseUrl, and it works. I added a regression test, too.

Steps to test

You could simply revert the fix I made and run the system test - it will fail. Alternatively, you could make a new Next project, change baseUrl to src, then update some imports to remove src - eg import 'src/styles/global.css' would become import 'styles/global.css', which is allowed since you've now got "baseUrl": "src".

How has the user experience changed?

It respects baseUrl and works as expected.

PR Tasks

@lmiller1990 lmiller1990 requested a review from a team April 3, 2023 05:31
@cypress
Copy link

cypress bot commented Apr 3, 2023

3 flaky tests on run #45231 ↗︎

0 5121 74 0 Flakiness 3

Details:

add default function
Project: cypress Commit: bf7771f457
Status: Passed Duration: 14:39 💡
Started: Apr 4, 2023 4:09 AM Ended: Apr 4, 2023 4:24 AM
Flakiness  cypress/e2e/cypress/cypress.cy.js • 3 flaky tests • 5x-driver-electron

View Output Video

Test Artifacts
... > correctly returns currentRetry Output Video
... > correctly returns currentRetry Output Video
... > correctly returns currentRetry Output Video

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings.

jsConfig: jsConfigResult.jsConfig,
// Required for Next.js > 13.2.0 to respect tsconfig.compilerOptions.baseUrl
resolvedBaseUrl: jsConfigResult.resolvedBaseUrl,
Copy link
Contributor Author

@lmiller1990 lmiller1990 Apr 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix. We could do ...jsConfigResult, but we don't know exactly what else is there (can change at any time), I think this is probably more explicit and maintainable.

Copy link
Contributor

@mike-plummer mike-plummer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work tracking this down ! 🥳

Two thoughts on the changelog entry:

  1. Should it reference "in Component Testing projects" just to be more explicit?
  2. Component testing broken with NextJS 13.2.1 #25951 is already referenced in the 12.8.0 changelog - should we add wording around "completed an edge case not covered in our original fix" or something to that effect?

Copy link
Contributor

@jordanpowell88 jordanpowell88 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Great job tracking this down @lmiller1990

@lmiller1990
Copy link
Contributor Author

@mike-plummer good idea, I updated the changelog.

@lmiller1990 lmiller1990 merged commit e8390f4 into develop Apr 6, 2023
@lmiller1990 lmiller1990 deleted the issue-25951-next-app branch April 6, 2023 03:09
astone123 pushed a commit to kgroat/cypress that referenced this pull request Apr 19, 2023
…6399)

* add test project

* styles

* pass resolvedBaseUrl

* make project more minimal

* build binaries

* changelog

* remove css

* pass supportedBrowsers to next webpack config

* handle case of missing getSupportedBrowsers function

* add default function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Component testing broken with NextJS 13.2.1
3 participants