Skip to content

Wrangler: update autoconfig logic to handle Next.js projects by using the new @opennextjs/cloudflare migrate command#12190

Merged
dario-piotrowicz merged 11 commits intomainfrom
dario/DEVX-2383/opennext-init
Jan 29, 2026
Merged

Wrangler: update autoconfig logic to handle Next.js projects by using the new @opennextjs/cloudflare migrate command#12190
dario-piotrowicz merged 11 commits intomainfrom
dario/DEVX-2383/opennext-init

Conversation

@dario-piotrowicz
Copy link
Copy Markdown
Member

@dario-piotrowicz dario-piotrowicz commented Jan 27, 2026

Fixes https://jira.cfdata.org/browse/DEVX-2383

This PR removes the OpenNext logic we have in the wrangler autoconfig flow in favour of using the newly introduced migrate command from @opennextjs/cloudflare


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
      • this flow is already tested in the experimental C3 e2es
      • to manually test the changes here I run C3, ensured that it uses the new migrate command and previewed the application locally
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: tracked elsewhere

A picture of a cute animal (not mandatory, but encouraged)


Open with Devin

… the new `@opennextjs/cloudflare migrate` command
@dario-piotrowicz dario-piotrowicz requested a review from a team as a code owner January 27, 2026 15:30
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jan 27, 2026

🦋 Changeset detected

Latest commit: fe581f5

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

View issue and 4 additional flags in Devin Review.

Open in Devin Review

Comment thread packages/wrangler/src/autoconfig/frameworks/next.ts Outdated
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jan 27, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@12190

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@12190

miniflare

npm i https://pkg.pr.new/miniflare@12190

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@12190

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@12190

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@12190

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@12190

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@12190

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@12190

wrangler

npm i https://pkg.pr.new/wrangler@12190

commit: fe581f5

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

View issue and 5 additional flags in Devin Review.

Open in Devin Review

Comment thread packages/wrangler/src/autoconfig/run.ts
Comment thread packages/wrangler/src/autoconfig/frameworks/index.ts Outdated
Comment thread packages/wrangler/src/autoconfig/frameworks/next.ts Outdated
Comment thread packages/wrangler/src/autoconfig/run.ts Outdated
Comment on lines +108 to +113
dryRunConfigurationResults?.wranglerConfig === null
? null
: {
...wranglerConfig,
...dryRunConfigurationResults?.wranglerConfig,
},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What about the scenario where dryRunConfigurationResults === undefined? Should it still show the wranglerConfig?

I guess what we are saying (at least how it worked before) is that if the dryRunConfigurationResults is undefined then we are just using the default one (i.e. wranglerConfig)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yes, dryRunConfigurationResults can be undefined only when a framework is not detected, in that case we want to generate the default wrangler config.

(PS: at this point anyways dryRunConfigurationResults cannot be undefined since we'd have detected a framework by now (even if just the Static one), I think the types here could be improved...)

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk Jan 28, 2026
Comment thread packages/wrangler/src/autoconfig/run.ts Outdated
Comment on lines +262 to +263
// If wranglerConfigToWrite is null the framework's tool is generating the wrangler config so we don't know
// if there is server side code or not, but likely there should be so we here assume that there is
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This comment is quite verbose. Can it be simplified?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

hopefully you find this better: 359e8c1

},
],
},
// `@opennextjs/cloudflare migrate` creates the wrangler config file
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't really understand why we're special casing Next here? Other framework adapt commands generate a wrangler.json, and autoconfig still works fine (adding a few default fields but otherwise being entirely overwritten by the framework fields). Was next broken without this change?

Does Next add $schema and observability?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't really understand why we're special casing Next here? Other framework adapt commands generate a wrangler.json, and autoconfig still works fine (adding a few default fields but otherwise being entirely overwritten by the framework fields)

If frameworks generate wrangler.jsonc files then I think we should revisit that, as we currently override it:

await writeFile(
resolve(autoConfigDetails.projectPath, "wrangler.jsonc"),
JSON.stringify(
{ ...wranglerConfig, ...configurationResults?.wranglerConfig },
null,
2
)
);

If a framework generates its own wrangler.jsonc config file then I think we should either honor it (as I am doing in this PR) or editing it, not completely overriding it.

Was next broken without this change?

Yes, the openNext migrate command adds various fields in the config (https://github.com/opennextjs/opennextjs-cloudflare/blob/6727373c31600b627e3c633b9bc4d24013927904/packages/cloudflare/templates/wrangler.jsonc#L11-L34) and with the old logic we were completely deleting them

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Does Next add $schema and observability?

It adds the $schema but not observability:
https://github.com/opennextjs/opennextjs-cloudflare/blob/6727373c31600b627e3c633b9bc4d24013927904/packages/cloudflare/templates/wrangler.jsonc#L2

That's my bad I can update it to also enable observability

Copy link
Copy Markdown
Member Author

@dario-piotrowicz dario-piotrowicz Jan 28, 2026

Choose a reason for hiding this comment

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

Updated to combine wrangler.json(c) files generated by the framework with our own: fe581f5

This should solve all the concerns both for Next.js and any other framework that can generate a wrangler config file

PS: for simplicity, wrangler.toml files are not supported here, also potential comments in wrangler.jsonc files are not preserved, I could add logic to also handle such cases if we want to (but that might be a bit involved, and potentially not really needed)

@github-project-automation github-project-automation Bot moved this from Approved to In Review in workers-sdk Jan 28, 2026
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Jan 28, 2026

Claude finished @dario-piotrowicz's task —— View job


Changeset Review

Reviewing changeset files for this PR...

  • Read changeset guidelines
  • Read changeset file(s)
  • Validate changeset content
  • Check for cute animals
  • Post review findings

⚠️ Issues found

The changeset .changeset/breezy-ends-bathe.md needs improvement:

1. Missing Body/Explanation

The changeset only has a title but no body explaining the change. According to the guidelines:

BODY: One or more paragraphs explaining the reason for the change and anything notable about the approach. Aim for more than one sentence but less than three paragraphs to keep it succinct and useful.

Recommendation: Add a body that explains:

  • Why this change was made (migrating from old OpenNext logic to the new @opennextjs/cloudflare migrate command)
  • What the user-facing impact is (if any)
  • Any notable implementation details

Example improvement:

---
"wrangler": patch
---

Update autoconfig logic to handle Next.js projects by using the new `@opennextjs/cloudflare migrate` command

The autoconfig flow for Next.js projects now delegates to `@opennextjs/cloudflare migrate` instead of maintaining custom OpenNext configuration logic. This ensures compatibility with the latest OpenNext tooling and reduces maintenance burden. The wrangler configuration generated by the migrate command is now preserved and merged with autoconfig's settings rather than being overwritten.

2. Version Type is Acceptable

The patch version is appropriate since this is an improvement to existing functionality without adding new user-facing features or breaking changes.

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

View issue and 9 additional flags in Devin Review.

Open in Devin Review

Comment thread packages/wrangler/src/autoconfig/frameworks/next.ts Outdated
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

View issue and 9 additional flags in Devin Review.

Open in Devin Review

Comment thread packages/wrangler/src/autoconfig/run.ts Outdated
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

View issue and 11 additional flags in Devin Review.

Open in Devin Review

Comment thread packages/wrangler/src/autoconfig/run.ts
@github-project-automation github-project-automation Bot moved this from In Review to Approved in workers-sdk Jan 29, 2026
@dario-piotrowicz dario-piotrowicz added this pull request to the merge queue Jan 29, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jan 29, 2026
@dario-piotrowicz dario-piotrowicz added this pull request to the merge queue Jan 29, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jan 29, 2026
@dario-piotrowicz dario-piotrowicz added this pull request to the merge queue Jan 29, 2026
@penalosa penalosa removed this pull request from the merge queue due to the queue being cleared Jan 29, 2026
@dario-piotrowicz dario-piotrowicz merged commit ce736b9 into main Jan 29, 2026
40 checks passed
@dario-piotrowicz dario-piotrowicz deleted the dario/DEVX-2383/opennext-init branch January 29, 2026 15:58
@github-project-automation github-project-automation Bot moved this from Approved to Done in workers-sdk Jan 29, 2026
@dario-piotrowicz dario-piotrowicz mentioned this pull request Feb 1, 2026
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants