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

refactor(template-compiler): move implicit stylesheet import and style token to template compiler #4147

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

jmsjtu
Copy link
Member

@jmsjtu jmsjtu commented Apr 12, 2024

Details

Fixes #3931

This will be a breaking change, the compile API now requires the file name, which is used to determine the css imports.

I've also expanded the config to accept namespace and name.

This change updates all the template compiler snapshots and I've separated them into 2 commits;

Does this pull request introduce a breaking change?

  • 💔 Yes, it does introduce a breaking change.

The @lwc/template-compiler compile function now requires the component's file name when compiling the template.

Does this pull request introduce an observable change?

  • 🔬 Yes, it does include an observable change.

GUS work item

W-15461766

@jmsjtu jmsjtu requested a review from a team as a code owner April 12, 2024 21:59
}

const compiled = compiler(src, config);
const compiled = compiler(src, filename, config);
Copy link
Member Author

Choose a reason for hiding this comment

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

The new snapshots all have the implicit imports, which can be noisey.

As an alternative we could add something to cut out the imports for certain snapshots.

I opted to leave it as-is for now to get opinions.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fine with the snapshots being a bit noisy. I actually prefer to see what the code actually looks like, rather than trying to hide boilerplate/repetition.

Comment on lines +48 to +56
const relPath = `./${path.basename(filename, path.extname(filename))}`;
const imports = IMPLICIT_STYLESHEET_IMPORTS.map((stylesheet) => {
const extension = stylesheet === IMPLICIT_STYLESHEETS ? '.css' : '.scoped.css?scoped=true';
return t.importDeclaration(
[t.importDefaultSpecifier(t.identifier(stylesheet))],
t.literal(`${relPath}${extension}`)
);
});

Copy link
Member Author

Choose a reason for hiding this comment

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

The reason we need the filename now is for these implicit imports

*/
scopeTokens: scopeTokens;

constructor(config: NormalizedConfig, filename: string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I understand why the filename isn't part of the config, but it strikes me as a bit odd... might be worth a comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated in the latest commit! - 85f8a18

Copy link
Contributor

@nolanlawson nolanlawson left a comment

Choose a reason for hiding this comment

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

This LGTM, although it is technically a breaking change, so we should save it for the 7.0.0 milestone.

I also opened some follow-up PRs for random off-topic things: #4151 #4149

I'm also astonished that the downstream LWR tests are passing. It would be good to do a sanity check of this change in LWR to make sure everything works correctly. (I suspect HMR may be broken, for instance.)

FYI @lpomerleau @kmbauer

@nolanlawson nolanlawson added this to the 7.0.0 milestone Apr 15, 2024
@jmsjtu
Copy link
Member Author

jmsjtu commented May 14, 2024

I compared the nucleus downstream test failures against the latest commit in master (c7bd1b7).

There will be a snapshot test failure for @communities/webruntime after this update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move template function implicit stylesheets and freezetemplate code generation to @lwc/template-compiler
2 participants