From efa606006f701e3b1ba81124e24b71250791e3fd Mon Sep 17 00:00:00 2001 From: Will Tonkin Date: Mon, 10 Dec 2018 16:50:33 +0100 Subject: [PATCH] fix: skip nested markup containers --- packages/react-from-markup/src/rehydrator.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/react-from-markup/src/rehydrator.ts b/packages/react-from-markup/src/rehydrator.ts index 0f0c3a0..ee23ebc 100644 --- a/packages/react-from-markup/src/rehydrator.ts +++ b/packages/react-from-markup/src/rehydrator.ts @@ -75,7 +75,13 @@ export default async ( const roots = Array.from( // TODO: allow setting a container identifier so multiple rehydration instances can exist container.querySelectorAll("[data-react-from-markup-container]") - ); + ).reduce((acc: Element[], root: Element) => { + // filter roots that are contained within other roots + if (!acc.some(r => r.contains(root))) { + acc.push(root); + } + return acc; + }, []); // TODO: solve race condition when a second rehydrate runs