Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partially revert 86c9ff1 Add static template hoisting to SSR #54

Merged
merged 1 commit into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/babel-plugin-jsx-dom-expressions/src/dom/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,9 @@ function transformAttributes(path, results) {
) {
// can only hydrate delegated events
hasHydratableEvent = true;
const events = path.state.events;
const events =
attribute.scope.getProgramParent().data.events ||
(attribute.scope.getProgramParent().data.events = new Set());
events.add(ev);
let handler = value.expression;
const resolveable = detectResolvableEventHandler(attribute, handler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ function registerTemplate(path, results) {
const { hydratable } = config;
let decl;
if (results.template.length) {
const templates = path.state.templates;
const templates =
path.scope.getProgramParent().data.templates ||
(path.scope.getProgramParent().data.templates = []);
let templateDef, templateId;
if ((templateDef = templates.find(t => t.template === results.template))) {
templateId = templateDef.id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import config from "../config";

// add to the top/bottom of the module.
export default path => {
if (path.state.events.size) {
if (path.scope.data.events) {
registerImportMethod(path, "delegateEvents");
path.node.body.push(
t.expressionStatement(
t.callExpression(t.identifier("_$delegateEvents"), [
t.arrayExpression(Array.from(path.state.events).map(e => t.stringLiteral(e)))
t.arrayExpression(Array.from(path.scope.data.events).map(e => t.stringLiteral(e)))
])
)
);
}
if (path.state.templates.length) {
if (path.scope.data.templates) {
const appendTemplates = config.generate === "ssr" ? appendTemplatesSSR : appendTemplatesDOM;
appendTemplates(path, path.state.templates);
appendTemplates(path, path.scope.data.templates);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,4 @@ export default path => {
}
path.skip();
}
path.state = {
templates: [],
events: new Set()
}
};
7 changes: 5 additions & 2 deletions packages/babel-plugin-jsx-dom-expressions/src/ssr/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export function createTemplate(path, result) {
template = t.arrayExpression(strings);
}

const found = path.state.templates.find(tmp => {
const templates =
path.scope.getProgramParent().data.templates ||
(path.scope.getProgramParent().data.templates = []);
const found = templates.find(tmp => {
if (t.isArrayExpression(tmp[1]) && t.isArrayExpression(template)) {
return tmp[1].elements.every(
(el, i) => template.elements[i] && el.value === template.elements[i].value
Expand All @@ -28,7 +31,7 @@ export function createTemplate(path, result) {
});
if (!found) {
id = path.scope.generateUidIdentifier("tmpl$");
path.state.templates.push([id, template]);
templates.push([id, template]);
} else id = found[0];

return t.callExpression(
Expand Down