diff --git a/.changeset/fast-kings-cheer.md b/.changeset/fast-kings-cheer.md new file mode 100644 index 000000000..34dd7ead3 --- /dev/null +++ b/.changeset/fast-kings-cheer.md @@ -0,0 +1,5 @@ +--- +'@vanilla-extract/recipes': minor +--- + +Handle option field that doesn't exist in config diff --git a/packages/recipes/src/createRuntimeFn.ts b/packages/recipes/src/createRuntimeFn.ts index f064aeda1..29a93fbea 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; diff --git a/tests/recipes/recipes.test.ts b/tests/recipes/recipes.test.ts index 6794b957c..b7d0240b6 100644 --- a/tests/recipes/recipes.test.ts +++ b/tests/recipes/recipes.test.ts @@ -24,6 +24,13 @@ describe('recipes', () => { ); }); + it('should not fall on arbitrary fields', () => { + // @ts-expect-error Field should be not defined in this test + expect(basic({ notHere: 'arbitrary-prop' })).toMatchInlineSnapshot( + `"recipes_basic__niwegb0 recipes_basic_spaceWithDefault_small__niwegb1"`, + ); + }); + it('should return requested variants', () => { expect( basic({