Skip to content

Commit 6673938

Browse files
committed
Refactor simple component caching
1 parent 923d9e9 commit 6673938

File tree

1 file changed

+15
-41
lines changed

1 file changed

+15
-41
lines changed

SSRtest/ModifiedReact.js

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,50 +2254,24 @@ var ReactDOMServerRenderer = function () {
22542254

22552255
for (let component in start) {
22562256
let tagStack = [];
2257-
<<<<<<< HEAD
2258-
=======
2259-
let pairs = {};
2260-
let end;
2261-
>>>>>>> 0f25537ae1db80b9c030058d253b1351c3dc4f1a
2262-
2263-
// update end index to end of tag
2264-
let tagEnd = out.indexOf('>', start[component]) + 1;
2265-
let openingTag = out.slice(start[component],tagEnd);
2266-
<<<<<<< HEAD
2267-
let end = tagEnd;
2268-
2269-
// Check if component is itself a self-closing tag (skip stack logic)
2270-
=======
2271-
2272-
end = tagEnd;
2273-
>>>>>>> 0f25537ae1db80b9c030058d253b1351c3dc4f1a
2274-
if (out[tagEnd - 2] !== '/') {
2275-
// push the opening tag onto the stack
2276-
tagStack.push(openingTag);
2277-
// getTags(end, component, start);
2278-
2279-
// while loop: while stack is not empty
2280-
while (tagStack.length !== 0) {
2281-
// move end index forward to next tag
2282-
end = out.indexOf('<', end);
2283-
let newTagEnd = out.indexOf('>', end) + 1;
2284-
// Check for self-closing tag (skip stack logic)
2285-
if (out[newTagEnd - 2] !== '/') {
2286-
if (out[end+1] !== '/') {
2287-
let newTag = out.slice(end, newTagEnd);
2288-
tagStack.push(newTag);
2289-
} else {
2290-
tagStack.pop();
2291-
}
2292-
}
2293-
end = newTagEnd;
2257+
let tagStart;
2258+
let tagEnd;
2259+
2260+
do {
2261+
if (!tagStart) tagStart = start[component];
2262+
else tagStart = (out[tagEnd] === '<') ? tagEnd : out.indexOf('<', tagEnd)
2263+
tagEnd = out.indexOf('>', tagStart) + 1;
2264+
// Skip stack logic for void/self-closing elements
2265+
if (out[tagEnd - 2] !== '/') {
2266+
// Push opening tags onto stack; pop closing tags off of stack
2267+
if (out[tagStart + 1] !== '/') tagStack.push(out.slice(tagStart, tagEnd));
2268+
else tagStack.pop();
22942269
}
2295-
}
2270+
} while (tagStack.length !== 0);
2271+
22962272
// cache component by slicing 'out'
2297-
cache.storage.set(component, out.slice(start[component], end));
2298-
// cache[component] = out.slice(start[component], end);
2273+
cache.storage.set(component, out.slice(start[component], tagEnd));
22992274
}
2300-
23012275
return out;
23022276
};
23032277

0 commit comments

Comments
 (0)