From c2bba5894ef127dae016cb90593f94d21958c6e4 Mon Sep 17 00:00:00 2001 From: Christoph Fricke Date: Fri, 12 Apr 2024 09:19:58 +0200 Subject: [PATCH 1/3] test(recipe): add reproduction for uncaught type error --- tests/recipes/recipes.test.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/recipes/recipes.test.ts b/tests/recipes/recipes.test.ts index 6794b957..d00e9a42 100644 --- a/tests/recipes/recipes.test.ts +++ b/tests/recipes/recipes.test.ts @@ -24,6 +24,13 @@ describe('recipes', () => { ); }); + it('should ignore unknown variants', () => { + const props = { other: 'unknown-option' } as Parameters[0]; + expect(basic(props)).toMatchInlineSnapshot( + `"recipes_basic__niwegb0 recipes_basic_spaceWithDefault_small__niwegb1"`, + ); + }); + it('should return requested variants', () => { expect( basic({ From 247366022e3134c24deaddece4f21fd433eaf792 Mon Sep 17 00:00:00 2001 From: Christoph Fricke Date: Fri, 12 Apr 2024 09:22:10 +0200 Subject: [PATCH 2/3] fix(recipe): runtimeFn to ignore unknown recipe options --- packages/recipes/src/createRuntimeFn.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/recipes/src/createRuntimeFn.ts b/packages/recipes/src/createRuntimeFn.ts index f064aeda..4ed8b8c1 100644 --- a/packages/recipes/src/createRuntimeFn.ts +++ b/packages/recipes/src/createRuntimeFn.ts @@ -45,7 +45,7 @@ export const createRuntimeFn = ( const selectionClassName = // @ts-expect-error - config.variantClassNames[variantName][selection]; + config.variantClassNames[variantName]?.[selection]; if (selectionClassName) { className += ' ' + selectionClassName; From c39a65edf8ad20c5df018c7e4b483868038c771d Mon Sep 17 00:00:00 2001 From: Christoph Fricke Date: Fri, 12 Apr 2024 09:24:09 +0200 Subject: [PATCH 3/3] chore: add changeset --- .changeset/calm-impalas-itch.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/calm-impalas-itch.md diff --git a/.changeset/calm-impalas-itch.md b/.changeset/calm-impalas-itch.md new file mode 100644 index 00000000..f60b4750 --- /dev/null +++ b/.changeset/calm-impalas-itch.md @@ -0,0 +1,5 @@ +--- +'@vanilla-extract/recipes': patch +--- + +Applying recipes now ignores unknown options instead of throwing a runtime TypeError.