Skip to content

Add support for custom component tag prefixes - #218

Open
ricardogobbosouza wants to merge 1 commit into
livewire:mainfrom
ricardogobbosouza:feat/register-component-prefixes
Open

ricardogobbosouza wants to merge 1 commit into
livewire:mainfrom
ricardogobbosouza:feat/register-component-prefixes

Conversation

@ricardogobbosouza

@ricardogobbosouza ricardogobbosouza commented Sep 17, 2026

Copy link
Copy Markdown

Summary

  • Adds a PrefixRegistry as the single source of truth for recognized component tag prefixes (x-, x:, flux: by default), replacing two duplicated hardcoded tables in Tokenizer and ComponentNode.
  • Exposes Blaze::registerPrefix(string $prefix, string $namespace = '', string $slotPrefix = 'x-slot') so consuming apps/packages can register their own tag prefixes (e.g. Blaze::registerPrefix('prefix:', namespace: 'prefix::') to recognize <prefix:icon>), mirroring how flux: already works.
  • ComponentNode no longer needs its own prefix→namespace lookup table: the Parser now threads the token's namespace straight through, so stripping the namespace back off for HTML fallback rendering is a plain str_starts_with/substr check.

Test plan

  • vendor/bin/pest — full suite passes (307 passed, 6 skipped pre-existing)
  • New tests/Parser/PrefixRegistryTest.php covering defaults, registration, and overwrite behavior
  • New/updated tests in TokenizerTest.php and ParserTest.php for a custom registered prefix
  • End-to-end test in BlazeManagerTest.php registering a namespace via Blade::anonymousComponentNamespace + Blaze::registerPrefix() and confirming the component compiles/inlines like a built-in prefix

@github-actions

Copy link
Copy Markdown
Contributor

Benchmark Result: Default

Attempt Blade Blaze Change
#1 * 74.49ms 14.00ms 81.2%
#2 73.36ms 13.59ms 81.5%
#3 72.52ms 13.56ms 81.3%
#4 73.32ms 13.55ms 81.5%
#5 73.81ms 13.68ms 81.5%
#6 72.85ms 13.67ms 81.2%
#7 74.29ms 13.57ms 81.7%
#8 73.61ms 13.67ms 81.4%
#9 73.78ms 13.67ms 81.5%
#10 72.99ms 13.58ms 81.4%
Snapshot 73.75ms 13.75ms 81.4%
Result 73.36ms (~) 13.59ms (~) 81.5% (~)

Median of 10 attempts (* = outlier, excluded from result), 5000 iterations x 10 rounds, 14.93s total

To run a specific benchmark, comment /benchmark <name>
attributes, aware, class, default, forwarding, merge, named-slots, no-attributes, slot, compilation

@ganyicz

ganyicz commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

Hi @ricardogobbosouza, thanks for contributing! Would you mind sharing the use case for this? Custom namespaces are already supported in both Laravel an Blaze with <x-namespace::.

@ricardogobbosouza

Copy link
Copy Markdown
Author

Hi @ricardogobbosouza, thanks for contributing! Would you mind sharing the use case for this? Custom namespaces are already supported in both Laravel an Blaze with <x-namespace::.

If a library like Flux is present, we cannot take advantage of Blaze.

For instance, <ui:text> is not recognized by Blaze; it only identifies the component when we use <x-ui::text>.

With this PR, we can add support for the ui: prefix, allowing the use of components like <ui:text> and, consequently, enabling the use of Blaze with libraries that adopt this pattern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants