Fix x-sort crash when container has a <template> with no .content#4819
Open
joshhanley wants to merge 2 commits intomainfrom
Open
Fix x-sort crash when container has a <template> with no .content#4819joshhanley wants to merge 2 commits intomainfrom
x-sort crash when container has a <template> with no .content#4819joshhanley wants to merge 2 commits intomainfrom
Conversation
`x-sort` auto-detects drag handles by scanning top-level `<template>` elements for `[x-sort:handle]` / `[wire:sort:handle]`. The scan unconditionally reads `tmpl.content.querySelector(...)`, which throws for any matched element that isn't an `HTMLTemplateElement`, e.g. a `<template>` in the SVG namespace or a custom element named `template`. Guarding with optional chaining on `.content` skips those entries.
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Placing a
flux:chartinside awire:sort:item(with nowire:sort:handle) breaks drag-to-reorder and throws in the console:The Problem
x-sortauto-detects whether the sort container uses drag handles. If no handle element is found directly, it scans nested<template>elements for one:querySelectorAll('template')matches every element with tag nametemplateregardless of namespace, but.contentonly exists onHTMLTemplateElement. Flux's chart hydrates its SVG from an HTML<template>and the hydrated<svg>contains nested<template>elements that were parsed in the SVG namespace, so they'reSVGElementinstances with no.contentproperty. The unconditional.querySelectorcall ontmpl.contentthrows.The Solution
Guard the property access with optional chaining so non-
HTMLTemplateElementmatches are skipped:Fixes livewire/flux#2578