livewire / livewire/volt

Using the word new somewhere (String, variable part, a.s.o) inside a Volt component can cause render problems.

Open
#155 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
423
Forks
36
PR merge metrics
No merged PRs in 30d

Description

### Volt Version

1.10.5

### Laravel Version

4.3.3

### PHP Version

8.2

### Database Driver & Version

_No response_

### Description

As soon as the word "new" appears in certain places of the volt component, the rendering gets weird.

I show 3 examples, but I had even more issues. I guess they all point to the same problem.

I upgraded from Livewire 3 to 4 and I do have numerous Volt components in my project. Quite a few are affected by this bug.

### Steps To Reproduce

### 1. Example

```
rules([
'count' => ['required', 'int', 'min:1', 'max:1000', new \App\Rules\GhpRule],
'gift' => ['boolean'],
]);

```

**becomes by the volt renderer**

```
rules([
'count' => ['required', 'int', 'min:1', 'max:1000', return new \App\Rules\GhpRule],
'gift' => ['boolean'],
]);

```
Which gives an exception.

### 2. Example

THIS DOES cause a render problem:

```
false,
]);

?>



```

THIS DOES NOT cause the render problem:

```
false,
]);

?>

```

All that I had to change was to change Previous new contribution to Previous contribution !

The render problem is that the return view function is injected inside the last php function found in the volt component. Which causes an exception at the protected keyword.

### 3. Example

`$new = computed(fn() => $this->forumThread);
`
**becomes by the volt renderer**

`return new = computed(fn() => $this->forumThread);
`
Which then throws an exception or course.

When I change this to:

`$newThread = computed(fn() => $this->forumThread);
`
everything works.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by inspecting the Volt renderer responsible for injecting the return view function, then reproduce the issue with the three component snippets in this report. Trace how the word "new" in rules, rendered text, and variable names changes the generated PHP; done means these examples render without malformed PHP or exceptions.

Written by the indexing model from the issue text.

Assessment

Tech stack
laravel, php
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.