Skip to content

Conversation

james-elicx
Copy link
Collaborator

When passing the --remote flag to our preview command, it would fail to properly populate the cache due to not targeting the remote bindings and missing a --preview flag for Workers KV / D1.

fixes #887

Changes:

  • Support both remote and local as modes for cache population in the preview command.
  • Pass the preview flag for KV / D1 cache population for the preview command.

Tested that cache population was working as expected with the following commands for the d1-tag-next example:

  • opennextjs-cloudflare preview --config wrangler.e2e.jsonc
  • opennextjs-cloudflare preview --config wrangler.e2e.jsonc --remote
  • opennextjs-cloudflare deploy --config wrangler.e2e.jsonc

Copy link

changeset-bot bot commented Sep 13, 2025

🦋 Changeset detected

Latest commit: bf128dc

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

This PR includes changesets to release 1 package
Name Type
@opennextjs/cloudflare Patch

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

pkg-pr-new bot commented Sep 13, 2025

Open in StackBlitz

npm i https://pkg.pr.new/@opennextjs/cloudflare@888

commit: bf128dc

@vicb
Copy link
Contributor

vicb commented Sep 15, 2025

Thanks for the fix @james-elicx

@dario-piotrowicz could you please take a look as you worked on the remote bindings.

Copy link
Contributor

@dario-piotrowicz dario-piotrowicz left a comment

Choose a reason for hiding this comment

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

Looks good to me 🙂

Although, tangential to the changes here, long term I would say that ideally remote bindings should be used instead of running the worker with --remote (unless there's a benefit/reason to do so?)

@vicb
Copy link
Contributor

vicb commented Sep 16, 2025

Although, tangential to the changes here, long term I would say that ideally remote bindings should be used instead of running the worker with --remote (unless there's a benefit/reason to do so?)

I think the plan is to remove --remote is the next major of wrangler @dario-piotrowicz right?

environment: args.env,
wranglerConfigPath: args.wranglerConfigPath,
cacheChunkSize: args.cacheChunkSize,
shouldUsePreviewNamespace: args.remote,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should shouldUsePreviewNamespace just be remote / useRemote

(c) =>
withPopulateCacheOptions(c).option("remote", {
type: "boolean",
default: false,
Copy link
Contributor

Choose a reason for hiding this comment

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

  -r, --remote                                     Run on the global Cloudflare network with access to production resources  [boolean] [default: false]

Add the "r" alias?

@@ -228,6 +238,7 @@ function populateD1TagCache(
"d1 execute",
D1_TAG_BINDING_NAME,
`--command "CREATE TABLE IF NOT EXISTS revalidations (tag TEXT NOT NULL, revalidatedAt INTEGER NOT NULL, UNIQUE(tag) ON CONFLICT REPLACE);"`,
...(populateCacheOptions.shouldUsePreviewNamespace ? ["--preview"] : ["--preview false"]),
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
...(populateCacheOptions.shouldUsePreviewNamespace ? ["--preview"] : ["--preview false"]),
...(populateCacheOptions.shouldUsePreviewNamespace ? ["--preview"] : []),

Because:

  • it's a boolean arg
  • to be consistent across the PR

Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment applies to l 207

Copy link
Contributor

@vicb vicb left a comment

Choose a reason for hiding this comment

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

@james-elicx I added a few minor comments.

The one most important thing is to add the "r" alias for "remote" IMO.

Thanks!

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.

[BUG] preview cli doesn't --preview flag to wrangler command
3 participants