diff --git a/src/services/ComponentsService.php b/src/services/ComponentsService.php index 88263ce..d969dab 100644 --- a/src/services/ComponentsService.php +++ b/src/services/ComponentsService.php @@ -212,10 +212,6 @@ public function create(string $value, array $variables = [], array|string $attri $attributes = ['id' => $attributes]; } - // Allow ID to be overridden, otherwise ensure random ID does not start with a digit (to avoid a JS error) - $id = $attributes['id'] ?? ('component-' . StringHelper::randomString(6)); - $config->id = $id; - $mergedVariables = array_merge( $variables, Sprig::$core->requests->getVariables() @@ -233,6 +229,10 @@ public function create(string $value, array $variables = [], array|string $attri $mergedVariables = $event->variables; $attributes = $event->attributes; + // Fall back to a random ID that does not start with a digit (to avoid a JS error) + $id = $attributes['id'] ?? ('component-' . StringHelper::randomString(6)); + $config->id = $id; + $componentObject = $this->createObject($value, $mergedVariables); if ($componentObject) {