Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@justinfagnani
Copy link
Collaborator

This make the module loader a class so that it can hold instance state about the cache, current vmContextID. This way more than one loader could be instantiated, which would be important for hosting multiple apps. This is working towards being able to introspect and modify the module cache too.

@justinfagnani justinfagnani requested a review from aomarks November 9, 2021 21:53
@changeset-bot
Copy link

changeset-bot bot commented Nov 9, 2021

🦋 Changeset detected

Latest commit: 881d471

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@google-cla google-cla bot added the cla: yes label Nov 9, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Nov 9, 2021

📊 Tachometer Benchmark Results

Summary

  • lit-element-list
  • lit-html-kitchen-sink
  • lit-html-repeat
  • lit-html-template-heavy
  • reactive-element-list

Results

tachometer-reporter-action v2 for Benchmarks

@justinfagnani justinfagnani marked this pull request as ready for review November 11, 2021 22:05
@justinfagnani justinfagnani changed the title [ssr] WIP: Improve module loader [ssr] Improve module loader and add a module cache that track imports. Nov 11, 2021

const modulePromise = (async () => {
const source = await fs.readFile(modulePath, 'utf-8');
// TODO: store and re-use cachedData:
Copy link
Member

Choose a reason for hiding this comment

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

Comment still relevant? It is cached now, right? Or if there's another layer of caching we could do, maybe elaborate on the comment (there is nothing called cachedData).

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 referring to Node's vm module cachedData, which should speed up repeated module creation in cases where we create fresh vm contexts. It's not related to our module cache. I updated the link and it seems like they added cachedData for modules now, so we can do this.

) {
// Override where we resolve lit-html from so that we always resolve to
// a single version of lit-html.
referrer = import.meta.url;
Copy link
Member

Choose a reason for hiding this comment

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

Does this force one version because it causes us to resolve relative to the top-level node_modules directory instead of a nested one?

What if there are two conflicting versions of Lit?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes.

We have a bit of work to do here to test behavior with multiple versions of Lit. Since Lit 2.0 we don't require instanceof anymore, so we might not even need this. It wouldn't be used in the "global" mode (where we path Node's global and don't load modules like this) anyway, but I don't want to change this quite yet.

// in their package.json to differentiate their ES module version.
packageFilter: (packageJson: PackageJSON) => {
packageJson.main =
packageJson.module ?? packageJson['jsnext:main'] ?? packageJson.main!;
Copy link
Member

Choose a reason for hiding this comment

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

I think ?? index.js should be the final fallback?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

resolve should already implement that then. Here we're just adding in some non-standard behavior to look at the module and jsnext:main fields.

referrer = import.meta.url;
}
const referencingModulePath = new URL(referrer).pathname;
const modulePath = resolve.sync(specifier, {
Copy link
Member

Choose a reason for hiding this comment

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

Will this handle package exports?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't know... I don't think this package has been updated in a while.

packages/labs/ssr/lib/
packages/labs/ssr/node_modules/
packages/labs/ssr/test/
packages/labs/ssr/test/**/*.js
Copy link
Member

Choose a reason for hiding this comment

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

Are these changes needed? Maybe they belong in another PR that adds tests? Same for .prettierignore.

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 PR does add tests. Some of your comments were on older version files though, so maybe you didn't see them?

Copy link
Member

Choose a reason for hiding this comment

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

Oops yeah I missed them somehow.

@justinfagnani
Copy link
Collaborator Author

@aomarks PTAL

@justinfagnani justinfagnani merged commit b42f6f0 into main Nov 12, 2021
@justinfagnani justinfagnani deleted the ssr-module-loader branch November 12, 2021 00:08
This was referenced Jan 5, 2022
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.

2 participants