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

Disable persistence by default (unless --enable-persistence passed) #321

Merged
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
11 changes: 11 additions & 0 deletions .changeset/two-coins-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"wrangler": patch
---

fix: disable local persistence by default & add `--experimental-enable-local-persistence` flag

BREAKING CHANGE:

When running `dev` locally any data stored in KV, Durable Objects or the cache are no longer persisted between sessions by default.

To turn this back on add the `--experimental-enable-local-persistence` at the command line.
5 changes: 5 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"printWidth": 80,
"singleQuote": false,
"semi": true
}
Comment on lines +1 to +5
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps this change is something to discuss in a separate PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see, this is to match the current settings, and override any user-level config that a developer might have...?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah my ~/.prettierrc is set to the opposite of all of these, so running prettier on anything exploded the diffs. I ran npm run prettify after adding this and it changed nothing, except the npm run check:format on CI still failed. Not sure why...

2 changes: 2 additions & 0 deletions packages/wrangler/src/__tests__/dev.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function renderDev({
compatibilityFlags,
usageModel,
buildCommand = {},
enableLocalPersistence = false,
}: Partial<DevProps>) {
return render(
<Dev
Expand All @@ -62,6 +63,7 @@ function renderDev({
compatibilityFlags={compatibilityFlags}
usageModel={usageModel}
bindings={bindings}
enableLocalPersistence={enableLocalPersistence}
/>
);
}
11 changes: 8 additions & 3 deletions packages/wrangler/src/dev.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export type DevProps = {
initialMode: "local" | "remote";
jsxFactory: undefined | string;
jsxFragment: undefined | string;
enableLocalPersistence: boolean;
bindings: CfWorkerInit["bindings"];
public: undefined | string;
assetPaths: undefined | AssetPaths;
Expand Down Expand Up @@ -102,6 +103,7 @@ function Dev(props: DevProps): JSX.Element {
site={props.assetPaths}
public={props.public}
port={port}
enableLocalPersistence={props.enableLocalPersistence}
/>
) : (
<Remote
Expand Down Expand Up @@ -184,13 +186,15 @@ function Local(props: {
public: undefined | string;
site: undefined | AssetPaths;
port: number;
enableLocalPersistence: boolean;
}) {
const { inspectorUrl } = useLocalWorker({
name: props.name,
bundle: props.bundle,
format: props.format,
bindings: props.bindings,
port: props.port,
enableLocalPersistence: props.enableLocalPersistence,
});
useInspector({ inspectorUrl, port: 9229, logToTerminal: false });
return null;
Expand All @@ -202,6 +206,7 @@ function useLocalWorker(props: {
format: CfScriptFormat;
bindings: CfWorkerInit["bindings"];
port: number;
enableLocalPersistence: boolean;
}) {
// TODO: pass vars via command line
const { bundle, format, bindings, port } = props;
Expand Down Expand Up @@ -238,9 +243,9 @@ function useLocalWorker(props: {
path.join(__dirname, "../miniflare-config-stubs/package.empty.json"),
"--port",
port.toString(),
"--kv-persist",
"--cache-persist",
"--do-persist",
...(props.enableLocalPersistence
? ["--kv-persist", "--cache-persist", "--do-persist"]
: []),
...Object.entries(bindings.vars || {}).flatMap(([key, value]) => {
return ["--binding", `${key}=${value}`];
}),
Expand Down
7 changes: 7 additions & 0 deletions packages/wrangler/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,10 @@ export async function main(argv: string[]): Promise<void> {
.option("jsx-fragment", {
describe: "The function that is called for each JSX fragment",
type: "string",
})
.option("experimental-enable-local-persistence", {
describe: "Enable persistence for this session (only for local mode)",
type: "boolean",
});
},
async (args) => {
Expand Down Expand Up @@ -608,6 +612,9 @@ export async function main(argv: string[]): Promise<void> {
initialMode={args.local ? "local" : "remote"}
jsxFactory={args["jsx-factory"] || envRootObj?.jsx_factory}
jsxFragment={args["jsx-fragment"] || envRootObj?.jsx_fragment}
enableLocalPersistence={
args["experimental-enable-local-persistence"] || false
}
accountId={config.account_id}
assetPaths={getAssetPaths(
config,
Expand Down