diff --git a/src/TwigComponent/src/ComponentFactory.php b/src/TwigComponent/src/ComponentFactory.php
index 02cf0cecf14..dc66412cf2b 100644
--- a/src/TwigComponent/src/ComponentFactory.php
+++ b/src/TwigComponent/src/ComponentFactory.php
@@ -102,9 +102,7 @@ public function mountFromObject(object $component, array $data, ComponentMetadat
continue;
}
- if (!\is_scalar($value) && null !== $value) {
- throw new \LogicException(sprintf('A "%s" prop was passed when creating the "%s" component. No matching %s property or mount() argument was found, so we attempted to use this as an HTML attribute. But, the value is not a scalar (it\'s a %s). Did you mean to pass this to your component or is there a typo on its name?', $key, $componentMetadata->getName(), $key, get_debug_type($value)));
- }
+ $data[$key] = $value;
}
return new MountedComponent(
diff --git a/src/TwigComponent/tests/Fixtures/User.php b/src/TwigComponent/tests/Fixtures/User.php
new file mode 100644
index 00000000000..eb25026072a
--- /dev/null
+++ b/src/TwigComponent/tests/Fixtures/User.php
@@ -0,0 +1,21 @@
+name;
+ }
+
+ public function getEmail(): string
+ {
+ return $this->email;
+ }
+}
\ No newline at end of file
diff --git a/src/TwigComponent/tests/Fixtures/templates/anonymous_component_none_scalar_prop.html.twig b/src/TwigComponent/tests/Fixtures/templates/anonymous_component_none_scalar_prop.html.twig
new file mode 100644
index 00000000000..a1c267e1f1c
--- /dev/null
+++ b/src/TwigComponent/tests/Fixtures/templates/anonymous_component_none_scalar_prop.html.twig
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/src/TwigComponent/tests/Fixtures/templates/components/UserCard.html.twig b/src/TwigComponent/tests/Fixtures/templates/components/UserCard.html.twig
new file mode 100644
index 00000000000..4a3e94dbaf2
--- /dev/null
+++ b/src/TwigComponent/tests/Fixtures/templates/components/UserCard.html.twig
@@ -0,0 +1,4 @@
+
+
{{ user.name }}
+
{{ user.email }}
+
\ No newline at end of file
diff --git a/src/TwigComponent/tests/Integration/ComponentExtensionTest.php b/src/TwigComponent/tests/Integration/ComponentExtensionTest.php
index 5c4c71148db..8d6dbabf455 100644
--- a/src/TwigComponent/tests/Integration/ComponentExtensionTest.php
+++ b/src/TwigComponent/tests/Integration/ComponentExtensionTest.php
@@ -12,6 +12,7 @@
namespace Symfony\UX\TwigComponent\Tests\Integration;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
+use Symfony\UX\TwigComponent\Tests\Fixtures\User;
use Twig\Environment;
/**
@@ -182,6 +183,16 @@ public function testRenderAnonymousComponentInNestedDirectory(): void
$this->assertStringContainsString('class="primary"', $output);
}
+ public function testRenderAnonymousComponentWithNonScalarProps(): void
+ {
+ $user = new User('Fabien', 'test@test.com');
+
+ $output = self::getContainer()->get(Environment::class)->render('anonymous_component_none_scalar_prop.html.twig', ['user' => $user]);
+
+ $this->assertStringContainsString('Fabien', $output);
+ $this->assertStringContainsString('test@test.com', $output);
+ }
+
private function renderComponent(string $name, array $data = []): string
{
return self::getContainer()->get(Environment::class)->render('render_component.html.twig', [
diff --git a/src/TwigComponent/tests/Integration/ComponentFactoryTest.php b/src/TwigComponent/tests/Integration/ComponentFactoryTest.php
index edbab16788a..c7211bf7afb 100644
--- a/src/TwigComponent/tests/Integration/ComponentFactoryTest.php
+++ b/src/TwigComponent/tests/Integration/ComponentFactoryTest.php
@@ -91,14 +91,6 @@ public function testExceptionThrownIfRequiredMountParameterIsMissingFromPassedDa
$this->createComponent('component_c');
}
- public function testExceptionThrownIfUnableToWritePassedDataToPropertyAndIsNotScalar(): void
- {
- $this->expectException(\LogicException::class);
- $this->expectExceptionMessage('But, the value is not a scalar (it\'s a stdClass)');
-
- $this->createComponent('component_a', ['propB' => 'B', 'service' => new \stdClass()]);
- }
-
public function testStringableObjectCanBePassedToComponent(): void
{
$attributes = $this->factory()->create('component_a', ['propB' => 'B', 'data-item-id-param' => new class() {