Skip to content

Commit 3c6ad5e

Browse files
WillTaylorDevCarmenPopoviciu
authored andcommitted
Update based on PR feedback
1 parent 31be8e9 commit 3c6ad5e

File tree

3 files changed

+21
-47
lines changed

3 files changed

+21
-47
lines changed

.changeset/tidy-kiwis-arrive.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
Warn users when using smart placement with Workers + Assets and `serve_directly` is set to `false`

packages/wrangler/src/__tests__/deploy.test.ts

Lines changed: 11 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4687,7 +4687,7 @@ addEventListener('fetch', event => {});`
46874687
`);
46884688
});
46894689

4690-
it("should warn when using smart placement with assets-first", async () => {
4690+
it("should warn when using smart placement with Worker first", async () => {
46914691
const assets = [
46924692
{ filePath: ".assetsignore", content: "*.bak\nsub-dir" },
46934693
{ filePath: "file-1.txt", content: "Content of file-1" },
@@ -4697,10 +4697,13 @@ addEventListener('fetch', event => {});`
46974697
{ filePath: "sub-dir/file-5.txt", content: "Content of file-5" },
46984698
];
46994699
writeAssets(assets, "assets");
4700+
writeWorkerSource({ format: "js" });
47004701
writeWranglerConfig({
4702+
main: "index.js",
47014703
assets: {
47024704
directory: "assets",
4703-
experimental_serve_directly: true,
4705+
experimental_serve_directly: false,
4706+
binding: "ASSETS",
47044707
},
47054708
placement: {
47064709
mode: "smart",
@@ -4713,57 +4716,21 @@ addEventListener('fetch', event => {});`
47134716
expectedAssets: {
47144717
jwt: "<<aus-completion-token>>",
47154718
config: {
4716-
serve_directly: true,
4719+
serve_directly: false,
47174720
},
47184721
},
4719-
expectedType: "none",
4722+
expectedMainModule: "index.js",
4723+
expectedBindings: [{ name: "ASSETS", type: "assets" }],
47204724
});
47214725

47224726
await runWrangler("deploy");
47234727

47244728
expect(std.warn).toMatchInlineSnapshot(`
4725-
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mUsing assets with smart placement turned on may result in poor performance.[0m
4729+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mTurning on Smart Placement in a Worker that is using assets and serve_directly set to false means that your entire Worker could be moved to run closer to your data source, and all requests will go to that Worker before serving assets.[0m
47264730
4727-
"
4728-
`);
4729-
});
4731+
This could result in poor performance as round trip times could increase when serving assets.
47304732
4731-
it("should warn when using smart placement with assets-first", async () => {
4732-
const assets = [
4733-
{ filePath: ".assetsignore", content: "*.bak\nsub-dir" },
4734-
{ filePath: "file-1.txt", content: "Content of file-1" },
4735-
{ filePath: "file-2.bak", content: "Content of file-2" },
4736-
{ filePath: "file-3.txt", content: "Content of file-3" },
4737-
{ filePath: "sub-dir/file-4.bak", content: "Content of file-4" },
4738-
{ filePath: "sub-dir/file-5.txt", content: "Content of file-5" },
4739-
];
4740-
writeAssets(assets, "assets");
4741-
writeWranglerConfig({
4742-
assets: {
4743-
directory: "assets",
4744-
experimental_serve_directly: true,
4745-
},
4746-
placement: {
4747-
mode: "smart",
4748-
},
4749-
});
4750-
const bodies: AssetManifest[] = [];
4751-
await mockAUSRequest(bodies);
4752-
mockSubDomainRequest();
4753-
mockUploadWorkerRequest({
4754-
expectedAssets: {
4755-
jwt: "<<aus-completion-token>>",
4756-
config: {
4757-
serve_directly: true,
4758-
},
4759-
},
4760-
expectedType: "none",
4761-
});
4762-
4763-
await runWrangler("deploy");
4764-
4765-
expect(std.warn).toMatchInlineSnapshot(`
4766-
"▲ [WARNING] Using assets with smart placement turned on may result in poor performance.
4733+
Read more: https://developers.cloudflare.com/workers/static-assets/binding/#smart-placement
47674734
47684735
"
47694736
`);

packages/wrangler/src/assets.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,14 +447,16 @@ export function validateAssetsArgsAndConfig(
447447
// Smart placement turned on when using assets
448448
if (
449449
config?.placement?.mode === "smart" &&
450-
config?.assets?.experimental_serve_directly
450+
config?.assets?.experimental_serve_directly === false
451451
) {
452452
logger.warn(
453-
"Using assets with smart placement turned on may result in poor performance."
453+
"Turning on Smart Placement in a Worker that is using assets and serve_directly set to false means that your entire Worker could be moved to run closer to your data source, and all requests will go to that Worker before serving assets.\n" +
454+
"This could result in poor performance as round trip times could increase when serving assets.\n\n" +
455+
"Read more: https://developers.cloudflare.com/workers/static-assets/binding/#smart-placement"
454456
);
455457
}
456458

457-
// User worker ahead of assets, but no assets binding provided
459+
// User Worker ahead of assets, but no assets binding provided
458460
if (
459461
"legacy" in args
460462
? args.assets?.assetConfig?.serve_directly === false &&

0 commit comments

Comments
 (0)