Skip to content

Commit 357f4bf

Browse files
Copilotbookernath
andcommitted
Implement generic metadata filtering for Makeswift runtime
- Replace simple favicon disabling with comprehensive metadata filtering - Filter out falsy values (empty strings, null, undefined) to use BigCommerce defaults - Always disable favicon to prefer store favicon from /favicon.ico route - Preserve arrays and meaningful boolean values - Recursively filter nested objects while avoiding empty objects - Handle edge cases: metadata=false, undefined, or empty objects Co-authored-by: bookernath <[email protected]>
1 parent 5e8ccd6 commit 357f4bf

File tree

2 files changed

+9376
-2
lines changed

2 files changed

+9376
-2
lines changed

core/lib/makeswift/makeswift-page-shim.tsx

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,64 @@
1111
import { Page as MakeswiftPage } from '@makeswift/runtime/next';
1212
import { ComponentPropsWithoutRef } from 'react';
1313

14+
/**
15+
* Filters metadata to only include meaningful values while preserving structure.
16+
* - Always disables favicon to prefer the store favicon from /favicon.ico
17+
* - Removes falsy values (empty strings, null, undefined) to use BigCommerce defaults
18+
* - Preserves nested objects and meaningful boolean values
19+
*/
20+
function filterMetadata(metadata: any): any {
21+
if (metadata === false) {
22+
return false;
23+
}
24+
25+
if (!metadata || typeof metadata !== 'object') {
26+
return { favicon: false };
27+
}
28+
29+
const filtered: any = { favicon: false };
30+
31+
for (const [key, value] of Object.entries(metadata)) {
32+
if (key === 'favicon') {
33+
// Always disable favicon to use store favicon
34+
continue;
35+
}
36+
37+
if (value === null || value === undefined) {
38+
// Skip null/undefined values to use BigCommerce defaults
39+
continue;
40+
}
41+
42+
if (typeof value === 'string' && value.trim() === '') {
43+
// Skip empty strings to use BigCommerce defaults
44+
continue;
45+
}
46+
47+
if (Array.isArray(value)) {
48+
// Preserve arrays as-is
49+
filtered[key] = value;
50+
continue;
51+
}
52+
53+
if (typeof value === 'object' && value !== null) {
54+
// Recursively filter nested objects (but not arrays)
55+
const filteredNested = filterMetadata(value);
56+
if (filteredNested !== false && Object.keys(filteredNested).length > 1) {
57+
// Only include nested objects if they have more than just the favicon property
58+
filtered[key] = filteredNested;
59+
}
60+
continue;
61+
}
62+
63+
// Include all other meaningful values (non-empty strings, numbers, booleans)
64+
filtered[key] = value;
65+
}
66+
67+
return filtered;
68+
}
69+
1470
export function MakeswiftPageShim(props: ComponentPropsWithoutRef<typeof MakeswiftPage>) {
15-
// Explicitly disable favicon to use the favicon from /favicon.ico route instead
16-
const metadata = props.metadata === false ? false : { ...props.metadata, favicon: false };
71+
const metadata = filterMetadata(props.metadata);
1772

1873
return <MakeswiftPage {...props} metadata={metadata} />;
1974
}

0 commit comments

Comments
 (0)