Skip to content

Commit

Permalink
Consider default prop values when checking attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnathonKoster committed Feb 8, 2025
1 parent 9c4fbd5 commit 5953f00
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Compiler/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,16 @@ protected function containsDynamicAttributes(ComponentNode $component): bool
return false;
}

protected function attributesSatisfyProps(ComponentNode $component, array $propNames): bool
protected function attributesSatisfyProps(ComponentState $component, array $propNames): bool
{
$attributeNames = collect($component->parameters)
$attributeNames = collect($component->node->parameters)
->map(fn (ParameterNode $param) => $param->materializedName)
->unique()
->flip()
->all();

$defaultProps = array_flip(array_keys($component->getPropDefaults()));

foreach ($propNames as $propName) {
if (isset($this->pendingProps[$propName])) {
// We can satisfy this one now. Let's clear it out.
Expand All @@ -80,6 +82,10 @@ protected function attributesSatisfyProps(ComponentNode $component, array $propN
continue;
}

if (isset($defaultProps[$propName])) {
continue;
}

$this->pendingProps[$propName] = true;
}

Expand Down Expand Up @@ -178,7 +184,7 @@ public function canRender(ComponentState $componentState): bool
return true;
}

if ($this->attributesSatisfyProps($componentState->node, $componentState->getAllPropNames())) {
if ($this->attributesSatisfyProps($componentState, $componentState->getAllPropNames())) {
return true;
}

Expand Down

0 comments on commit 5953f00

Please sign in to comment.