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

fix(ssr): fix expression scoping and other small fixes #4702

Merged
merged 3 commits into from
Oct 25, 2024

Conversation

nolanlawson
Copy link
Collaborator

Details

Fixes attribute value expression rendering inside of loops (e.g. for:each). Also fixes some other minor unrelated stuff.

Does this pull request introduce a breaking change?

  • 😮‍💨 No, it does not introduce a breaking change.

Does this pull request introduce an observable change?

  • 🤞 No, it does not introduce an observable change.

@nolanlawson nolanlawson requested a review from a team as a code owner October 25, 2024 18:43
@@ -348,6 +349,7 @@ export default function lwc(pluginOptions: RollupLwcOptions = {}): Plugin {
enableStaticContentOptimization: pluginOptions.enableStaticContentOptimization,
}),
targetSSR,
ssrMode,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was not piped through before.

} from 'estree';

export const bImportHtmlEscape = esTemplate`
import { htmlEscape } from '@lwc/shared';
import { htmlEscape } from '@lwc/ssr-runtime';
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's simpler just to have everything at runtime imported from ssr-runtime, rather than introducing more dependencies at runtime.

@@ -43,7 +43,7 @@
}
}
},
"dependencies": {
"devDependencies": {
Copy link
Collaborator Author

@nolanlawson nolanlawson Oct 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making this a devDep means that it's bundled into ssr-runtime which just makes things simpler (e.g. swapping packages in Tachometer tests). Plus this is what we do for engine-dom and engine-server.

return cxt.isLocalVar(scopeReferencedId?.name)
? expression
: b.memberExpression(b.identifier('instance'), expression);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted out from for-each.ts.

if (valueType === 'string') {
yield \`="\${prefix}\${htmlEscape(attrOrPropValue, true)}"\`;
yield \`="\${prefix}\${htmlEscape(attrValue, true)}"\`;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a prop so don't call it a prop.

…-nested-each/modules/x/component/component.html

Co-authored-by: Eugene Kashida <ekashida@gmail.com>
@nolanlawson nolanlawson merged commit cd41384 into master Oct 25, 2024
11 checks passed
@nolanlawson nolanlawson deleted the nolan/iters-ssr branch October 25, 2024 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants