Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The scenario
When using
flux:avatarwith Blaze, passing in dynamic variables, the component breaks.The problem
When Blaze renders the component, it replaces the dynamic variable with a placeholder:
This produces the output above, displaying
Atas the initials.Normally, Blaze would restore placeholders found in the output to something like
{{ $name }}.But because the placeholder was cut off to the first two letters, Blaze won't find it.
The solution
I decided the best solution at this time is to remove
@blazecompletely until we have a better solution for a such a dynamic component as avatar is in Blaze.I've attempted multiple solutions, both in Flux itself and by adding features to Blaze but none was ideal.
1. Using
@unblazeWe could refactor and move the dynamic parts from
@phpblocksto be inside
@unblaze:And this should work in theory, but it would require a significant refactoring and introduction of unprecedented patterns.
The biggest issue is the colors, which either need to remain in the blade file to be picked up by tailwind or to be whitelisted.
These classes are then passed into the parent div attributes so this entire part would need to be in an
@unblazeblock above the markup:I abandoned this solution as it was too complicated, messy and unprecedented.
2. Automatically abort folding
The core issue is that when Blaze doesn't find the cut-off placeholder, it will consider the fold as successful.
We could change this behavior and abort fold when a placholder is not found in the output.
Which is probably a good feature to have in Blaze and I can submit a PR for that.
But I found multiple ways this would break anyway:
a) If the user also passes
srcattribute, thenamewill appear inaltuncut, bypassing this check.b) When folding is aborted, Blaze will resort to memoization, resulting in repeating initials.
c) If Blaze suceeds the fold and
srcis passed in, it will only render the<img>tag, completely dropping the initials which are often used as a fallback when image is not available3. Manually abort folding
I added a new
Blaze::abort()feature we could use when we detect that the component should use dynamic parts:This would stop Blaze from both folding and memoization and leave the component untouched.
Again, this might be a good feature to have in Blaze and I can submit a PR for it.
Although, it's still brittle as the php code containing the abort will never truly run in runtime.
In the above example the abort will never be hit because Blaze will replace all dynamic variables with string.
And again, we loose the fallback if
$user->avataror$user->initialsisnull.Fixes #2108