@@ -142,16 +142,19 @@ You can fix the json schema or skip this error by calling createHeadlessForm(sch
142142 return getInputTypeFromSchema ( type || schema . type || 'string' , schema )
143143}
144144
145- // Cache converted options by content hash (works even when schemas are cloned)
146- const optionsByContent = new Map < string , Array < FieldOption > > ( )
145+ const optionsMap = new Map < string , Array < FieldOption > > ( )
147146
148- // Create content hash from options array (uses length + sample for speed)
147+ /**
148+ * Create a hash from options array for caching
149+ * @param opts - The options to hash
150+ * @returns The hash
151+ */
149152function hashOptions ( opts : JsfSchema [ ] ) : string {
150153 if ( ! opts . length ) {
151154 return '0'
152155 }
153156
154- // Extract the const value from a schema option for hashing
157+ // Extract the const value from an option
155158 const extractValue = ( option : JsfSchema ) => {
156159 return ( typeof option === 'object' && option !== null ) ? option . const : option
157160 }
@@ -161,7 +164,7 @@ function hashOptions(opts: JsfSchema[]): string {
161164 const middle = opts [ Math . floor ( length / 2 ) ]
162165 const end = opts [ length - 1 ]
163166
164- // Sample first, middle, last options for a lightweight but reliable hash
167+ // Sample 3 parts of the array for a reliable hash
165168 const sampledValues = [
166169 extractValue ( start ) ,
167170 extractValue ( middle ) ,
@@ -182,14 +185,12 @@ function hashOptions(opts: JsfSchema[]): string {
182185 * If it doesn't, we skip the option.
183186 */
184187function convertToOptions ( nodeOptions : JsfSchema [ ] ) : Array < FieldOption > {
185- // Check cache by content hash (works even when schemas are cloned)
186188 const hash = hashOptions ( nodeOptions )
187- const cached = optionsByContent . get ( hash )
189+ const cached = optionsMap . get ( hash )
188190 if ( cached ) {
189191 return cached
190192 }
191193
192- // Convert options
193194 const converted = nodeOptions
194195 . filter ( ( option ) : option is NonBooleanJsfSchema =>
195196 option !== null && typeof option === 'object' && option . const !== null ,
@@ -214,8 +215,7 @@ function convertToOptions(nodeOptions: JsfSchema[]): Array<FieldOption> {
214215 return { ...result , ...presentation , ...rest }
215216 } )
216217
217- // Cache for future use
218- optionsByContent . set ( hash , converted )
218+ optionsMap . set ( hash , converted )
219219 return converted
220220}
221221
0 commit comments