11ty / webc

Single File Web Components
MIT License
1.3k stars 36 forks source link

webc:if doesn't preclude the need for optional chaining #191

Open riskygit opened 10 months ago

riskygit commented 10 months ago
  <tail-cta webc:if="tail_cta" 
    :@lead="tail_cta?.lead"
    :@logos="tail_cta?.logos" 
    :@href="tail_cta?.href ?? '/get-started/'" 
    :@button-text="tail_cta?.button_text ?? 'Book a call'"
  ></tail-cta>

If I remove any of the ?.s, this happens regardless of whether the value is undefined:

[11ty] Problem writing Eleventy templates: (more in DEBUG output)
[11ty] 1. Having trouble writing to "dist/index.html" from "./src/index.webc" (via EleventyTemplateError)
[11ty] 2. Evaluating a dynamic prop failed: `:@button-text="tail_cta.button_text ?? 'Book a call'"`.
[11ty] Original error message: Cannot read properties of undefined (reading 'button_text') (via Error)
[11ty]
[11ty] Original error stack trace: Error: Evaluating a dynamic prop failed: `:@button-text="tail_cta.button_text ?? 'Book a call'"`.
[11ty] Original error message: Cannot read properties of undefined (reading 'button_text')

Doesn't make sense to me.