Skip to content

Commit 5a47d35

Browse files
committed
feat: (resolves #320) disable persistence by default
feat: Added —experimental-enable-local-persistence flag to turn back on chore: added project-level .prettierrc, otherwise system-wide settings cause massive diffs chore: added changeset
1 parent 53c6318 commit 5a47d35

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-3
lines changed

.changeset/two-coins-compare.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Disabled local persistence by default & added --experimental-enable-local-persistence flag

.prettierrc

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"printWidth": 80,
3+
"singleQuote": false,
4+
"semi": true
5+
}

packages/wrangler/src/__tests__/dev.test.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ function renderDev({
4444
compatibilityFlags,
4545
usageModel,
4646
buildCommand = {},
47+
enableLocalPersistence = false,
4748
}: Partial<DevProps>) {
4849
return render(
4950
<Dev
@@ -62,6 +63,7 @@ function renderDev({
6263
compatibilityFlags={compatibilityFlags}
6364
usageModel={usageModel}
6465
bindings={bindings}
66+
enableLocalPersistence={enableLocalPersistence}
6567
/>
6668
);
6769
}

packages/wrangler/src/dev.tsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export type DevProps = {
4040
initialMode: "local" | "remote";
4141
jsxFactory: undefined | string;
4242
jsxFragment: undefined | string;
43+
enableLocalPersistence: boolean;
4344
bindings: CfWorkerInit["bindings"];
4445
public: undefined | string;
4546
assetPaths: undefined | AssetPaths;
@@ -102,6 +103,7 @@ function Dev(props: DevProps): JSX.Element {
102103
site={props.assetPaths}
103104
public={props.public}
104105
port={port}
106+
enableLocalPersistence={props.enableLocalPersistence}
105107
/>
106108
) : (
107109
<Remote
@@ -184,13 +186,15 @@ function Local(props: {
184186
public: undefined | string;
185187
site: undefined | AssetPaths;
186188
port: number;
189+
enableLocalPersistence: boolean;
187190
}) {
188191
const { inspectorUrl } = useLocalWorker({
189192
name: props.name,
190193
bundle: props.bundle,
191194
format: props.format,
192195
bindings: props.bindings,
193196
port: props.port,
197+
enableLocalPersistence: props.enableLocalPersistence,
194198
});
195199
useInspector({ inspectorUrl, port: 9229, logToTerminal: false });
196200
return null;
@@ -202,6 +206,7 @@ function useLocalWorker(props: {
202206
format: CfScriptFormat;
203207
bindings: CfWorkerInit["bindings"];
204208
port: number;
209+
enableLocalPersistence: boolean;
205210
}) {
206211
// TODO: pass vars via command line
207212
const { bundle, format, bindings, port } = props;
@@ -238,9 +243,9 @@ function useLocalWorker(props: {
238243
path.join(__dirname, "../miniflare-config-stubs/package.empty.json"),
239244
"--port",
240245
port.toString(),
241-
"--kv-persist",
242-
"--cache-persist",
243-
"--do-persist",
246+
...(props.enableLocalPersistence
247+
? ["--kv-persist", "--cache-persist", "--do-persist"]
248+
: []),
244249
...Object.entries(bindings.vars || {}).flatMap(([key, value]) => {
245250
return ["--binding", `${key}=${value}`];
246251
}),

packages/wrangler/src/index.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,10 @@ export async function main(argv: string[]): Promise<void> {
541541
.option("jsx-fragment", {
542542
describe: "The function that is called for each JSX fragment",
543543
type: "string",
544+
})
545+
.option("experimental-enable-local-persistence", {
546+
describe: "Enable persistence for this session (only for local mode)",
547+
type: "boolean",
544548
});
545549
},
546550
async (args) => {
@@ -608,6 +612,9 @@ export async function main(argv: string[]): Promise<void> {
608612
initialMode={args.local ? "local" : "remote"}
609613
jsxFactory={args["jsx-factory"] || envRootObj?.jsx_factory}
610614
jsxFragment={args["jsx-fragment"] || envRootObj?.jsx_fragment}
615+
enableLocalPersistence={
616+
args["experimental-enable-local-persistence"] || false
617+
}
611618
accountId={config.account_id}
612619
assetPaths={getAssetPaths(
613620
config,

0 commit comments

Comments
 (0)