diff --git a/packages/svelte/src/compiler/phases/3-transform/client/visitors/RegularElement.js b/packages/svelte/src/compiler/phases/3-transform/client/visitors/RegularElement.js index b457c19cb3..6e33bda5e3 100644 --- a/packages/svelte/src/compiler/phases/3-transform/client/visitors/RegularElement.js +++ b/packages/svelte/src/compiler/phases/3-transform/client/visitors/RegularElement.js @@ -390,39 +390,8 @@ export function RegularElement(node, context) { ...rich_child_state.after_update ]); - // Create the text fallback branch (for legacy browsers) - // Extract all text/expression content recursively from the children - const text_content = extract_text_content(trimmed); - - /** @type {typeof state} */ - const text_child_state = { ...state, init: [], update: [], after_update: [] }; - - if (text_content.length > 0) { - const { value, has_state } = build_template_chunk(text_content, context, text_child_state); - const update = b.stmt(b.assignment('=', b.member(context.state.node, 'textContent'), value)); - - if (has_state) { - text_child_state.update.push(update); - } else { - text_child_state.init.push(update); - } - } - - const text_fn_body = b.block([ - ...text_child_state.init, - ...(text_child_state.update.length > 0 ? [build_render_statement(text_child_state)] : []), - ...text_child_state.after_update - ]); - child_state.init.push( - b.stmt( - b.call( - '$.rich_option', - context.state.node, - b.arrow([], rich_fn_body), - b.arrow([], text_fn_body) - ) - ) + b.stmt(b.call('$.rich_option', context.state.node, b.arrow([], rich_fn_body))) ); } else { /** @type {Expression} */ @@ -789,28 +758,3 @@ function build_element_special_value_attribute( state.init.push(b.stmt(b.call('$.init_select', node_id))); } } - -/** - * Recursively extracts all Text and ExpressionTag nodes from a tree of nodes. - * This is used to build the text-only fallback for rich options in legacy browsers. - * @param {AST.SvelteNode[]} nodes - * @returns {Array} - */ -function extract_text_content(nodes) { - /** @type {Array} */ - const result = []; - - for (const node of nodes) { - if (node.type === 'Text' || node.type === 'ExpressionTag') { - result.push(node); - } else if ('fragment' in node && node.fragment) { - // Recursively extract from elements with fragments (like RegularElement) - result.push(...extract_text_content(node.fragment.nodes)); - } else if ('children' in node && Array.isArray(node.children)) { - // Handle other node types with children - result.push(...extract_text_content(node.children)); - } - } - - return result; -} diff --git a/packages/svelte/src/internal/client/dom/elements/rich-option.js b/packages/svelte/src/internal/client/dom/elements/rich-option.js index 11d546d5cd..817815ac9c 100644 --- a/packages/svelte/src/internal/client/dom/elements/rich-option.js +++ b/packages/svelte/src/internal/client/dom/elements/rich-option.js @@ -6,10 +6,9 @@ import { check_rich_option_support, create_text } from '../operations.js'; * Modern browsers preserve HTML inside options, while older browsers strip it to text only. * * @param {HTMLOptionElement} option The option element - * @param {() => void} rich_fn Function to process rich HTML content (modern browsers) - * @param {() => void} text_fn Function to process text-only content (legacy browsers) + * @param {() => void} render Function to render the option content */ -export function rich_option(option, rich_fn, text_fn) { +export function rich_option(option, render) { var dominated = !check_rich_option_support(); var was_hydrating = hydrating; @@ -23,7 +22,7 @@ export function rich_option(option, rich_fn, text_fn) { option.appendChild(create_text()); } - rich_fn(); + render(); } finally { if (was_hydrating) { set_hydrating(true);