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

Don't throw for missing preview ids in local dev mode #3901

Merged
merged 3 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/bright-badgers-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Only require preview_id and preview_bucket_name in remote dev mode
14 changes: 7 additions & 7 deletions packages/wrangler/src/dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -844,14 +844,14 @@ function getBindings(
const bindings = {
kv_namespaces: [
...(configParam.kv_namespaces || []).map(
({ binding, preview_id, id: _id }) => {
// In `dev`, we make folks use a separate kv namespace called
({ binding, preview_id, id }) => {
// In remote `dev`, we make folks use a separate kv namespace called
// `preview_id` instead of `id` so that they don't
// break production data. So here we check that a `preview_id`
// has actually been configured.
// This whole block of code will be obsoleted in the future
// when we have copy-on-write for previews on edge workers.
if (!preview_id) {
if (!preview_id && !local) {
// TODO: This error has to be a _lot_ better, ideally just asking
// to create a preview namespace for the user automatically
throw new Error(
Expand All @@ -860,7 +860,7 @@ function getBindings(
}
return {
binding,
id: preview_id,
id: preview_id ?? id,
};
}
),
Expand Down Expand Up @@ -889,17 +889,17 @@ function getBindings(
],
r2_buckets: [
...(configParam.r2_buckets?.map(
({ binding, preview_bucket_name, bucket_name: _bucket_name }) => {
({ binding, preview_bucket_name, bucket_name }) => {
// same idea as kv namespace preview id,
// same copy-on-write TODO
if (!preview_bucket_name) {
if (!preview_bucket_name && !local) {
throw new Error(
`In development, you should use a separate r2 bucket than the one you'd use in production. Please create a new r2 bucket with "wrangler r2 bucket create <name>" and add its name as preview_bucket_name to the r2_buckets "${binding}" in your wrangler.toml`
);
}
return {
binding,
bucket_name: preview_bucket_name,
bucket_name: preview_bucket_name ?? bucket_name,
};
}
) || []),
Expand Down