Skip to content

Commit

Permalink
Turn namespaces into a stack inside toVdom
Browse files Browse the repository at this point in the history
  • Loading branch information
DAreRodz committed Dec 13, 2023
1 parent 9aa30f1 commit 6699797
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/interactivity/src/vdom.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { directivePrefix as p } from './constants';
const ignoreAttr = `data-${ p }-ignore`;
const islandAttr = `data-${ p }-interactive`;
const fullPrefix = `data-${ p }-`;
let namespace = null;
const namespaces = [];
const currentNamespace = () => namespaces[ namespaces.length - 1 ] ?? null;

// Regular expression for directive parsing.
const directiveParser = new RegExp(
Expand Down Expand Up @@ -79,7 +80,7 @@ export function toVdom( root ) {
} catch ( e ) {}
if ( n === islandAttr ) {
island = true;
namespace = value?.namespace ?? null;
namespaces.push( value?.namespace ?? null );
} else {
directives.push( [ n, ns, value ] );
}
Expand Down Expand Up @@ -107,7 +108,7 @@ export function toVdom( root ) {
directiveParser.exec( name );
if ( ! obj[ prefix ] ) obj[ prefix ] = [];
obj[ prefix ].push( {
namespace: ns ?? namespace,
namespace: ns ?? currentNamespace(),
value,
suffix,
} );
Expand All @@ -127,6 +128,9 @@ export function toVdom( root ) {
treeWalker.parentNode();
}

// Restore previous namespace.
if ( island ) namespaces.pop();

return [ h( node.localName, props, children ) ];
}

Expand Down

0 comments on commit 6699797

Please sign in to comment.