diff --git a/src/Model/TemplateEngine/Decorator/InspectorHints.php b/src/Model/TemplateEngine/Decorator/InspectorHints.php index c74199e9..d6595d7d 100644 --- a/src/Model/TemplateEngine/Decorator/InspectorHints.php +++ b/src/Model/TemplateEngine/Decorator/InspectorHints.php @@ -61,12 +61,50 @@ public function __construct( public function render(BlockInterface $block, $templateFile, array $dictionary = []): string { $result = $this->subject->render($block, $templateFile, $dictionary); + $trimmedResult = trim($result); // Only inject attributes if there's actual HTML content - if (empty(trim($result))) { + if (empty($trimmedResult)) { return $result; } + // Do not wrap if content looks like JSON (also check for common JSON patterns) + if (str_starts_with($trimmedResult, '{') || + str_starts_with($trimmedResult, '[') || + (str_starts_with($trimmedResult, '"') && str_contains($trimmedResult, '":{"'))) { + return $result; + } + + // Do not wrap if content is a script tag (start allows attributes or multiple tags) + if (stripos($trimmedResult, '\n%s\n", + "%s", $jsonMetadata, $html, $wrapperId diff --git a/src/Model/TemplateEngine/Plugin/InspectorHints.php b/src/Model/TemplateEngine/Plugin/InspectorHints.php index 31e74cc0..6455c671 100644 --- a/src/Model/TemplateEngine/Plugin/InspectorHints.php +++ b/src/Model/TemplateEngine/Plugin/InspectorHints.php @@ -6,6 +6,7 @@ use Magento\Developer\Helper\Data as DevHelper; use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\Request\Http; use Magento\Framework\App\State; use Magento\Framework\View\TemplateEngineFactory; use Magento\Framework\View\TemplateEngineInterface; @@ -32,25 +33,30 @@ class InspectorHints private State $state; + private Http $request; + /** * @param ScopeConfigInterface $scopeConfig * @param StoreManagerInterface $storeManager * @param DevHelper $devHelper * @param InspectorHintsFactory $inspectorHintsFactory * @param State $state + * @param Http $request */ public function __construct( ScopeConfigInterface $scopeConfig, StoreManagerInterface $storeManager, DevHelper $devHelper, InspectorHintsFactory $inspectorHintsFactory, - State $state + State $state, + Http $request ) { $this->scopeConfig = $scopeConfig; $this->storeManager = $storeManager; $this->devHelper = $devHelper; $this->inspectorHintsFactory = $inspectorHintsFactory; $this->state = $state; + $this->request = $request; } /** @@ -70,6 +76,17 @@ public function afterCreate( return $invocationResult; } + // Disable for AJAX/API requests (including Magewire) + if ($this->request->isXmlHttpRequest()) { + return $invocationResult; + } + + // Block any magewire/livewire AJAX endpoints only + $requestUri = $this->request->getRequestUri(); + if ($requestUri && preg_match('/\/(magewire|livewire)\//i', $requestUri)) { + return $invocationResult; + } + // Check if inspector is enabled in configuration $storeCode = $this->storeManager->getStore()->getCode(); if (!$this->scopeConfig->isSetFlag(self::XML_PATH_INSPECTOR_ENABLED, ScopeInterface::SCOPE_STORE, $storeCode)) { diff --git a/src/view/frontend/web/js/inspector.js b/src/view/frontend/web/js/inspector.js index 60ea1be5..a60fe92f 100644 --- a/src/view/frontend/web/js/inspector.js +++ b/src/view/frontend/web/js/inspector.js @@ -399,7 +399,7 @@ document.addEventListener('alpine:init', () => { this.isPickerActive = true; document.addEventListener('mousemove', this.mouseMoveHandler); document.addEventListener('click', this.clickHandler, false); // Don't use capture - document.body.style.cursor = 'crosshair'; + // Cursor is set dynamically in handleMouseMove based on inspectability }, /** @@ -443,16 +443,26 @@ document.addEventListener('alpine:init', () => { // Don't update if mouse is over the floating button if (this.floatingButton && this.floatingButton.contains(e.target)) { + document.body.style.cursor = 'crosshair'; return; } // Don't update if mouse is over the info badge if (this.infoBadge && this.infoBadge.contains(e.target)) { + document.body.style.cursor = 'crosshair'; return; } const element = this.findInspectableElement(e.target); + // Update cursor based on inspectability + if (element) { + document.body.style.cursor = 'crosshair'; + } else if (e.target && !e.target.classList.contains('mageforge-inspector') && !e.target.closest('.mageforge-inspector')) { + // Show"not-allowed" cursor for non-inspectable elements (protected Magewire components) + document.body.style.cursor = 'not-allowed'; + } + // Clear any existing hover timeout if (this.hoverTimeout) { clearTimeout(this.hoverTimeout);