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

Skip to content

Conversation

@AndrewJakubowicz
Copy link
Contributor

@AndrewJakubowicz AndrewJakubowicz commented Oct 20, 2023

Fixes: #2549

Context

When the eleventy ssr plugin loads modules concurrently, it would previously fail with an error. Something like:

Error: request for '@lit/reactive-element' is not yet fulfilled
        at SourceTextModule.link (node:internal/vm/module:198:17)
        at ModuleLoader.importModule (/home/aomarks/work/wireit-lit/packages/labs/ssr/src/lib/module-loader.ts:107:7)
        at async Promise.all (index 1)

Investigating this issue I found:

Solution is to closer match the spec. LoadRequestedModules should prepare module for linking by loading all dependencies.
Then when Link is called, LoadRequestedModules must have completed.

Theory

Before linking our code does:

async importModule(...){
    ...
    const result = await this._loadModule(specifier, referrerPath); // <--- `LoadRequestedModules`
    const module = result.module as vm.Module;
    if (module.status === 'unlinked') {
      await module.link(this._linker); // <--- `Link`
    }
   ...
}

However previously our _loadModule method did not load all dependencies, relying on module.link to load the dependencies. This seems to work when not loading multiple modules concurrently.

But, to allow multiple modules to load concurrently I've added some additional module loading logic to _loadModule so dependencies get loaded.

The result is that by the time module.link is reached, all modules should have been loaded.

Test plan

I added a unit test which throws Error: request for 'XXXX' is not yet fulfilled without the fix.

Risk

There is a risk that this adds a regression to the eleventy SSR plugin if something isn't quite right.

@changeset-bot
Copy link

changeset-bot bot commented Oct 20, 2023

🦋 Changeset detected

Latest commit: 8b14849

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

This PR includes changesets to release 2 packages
Name Type
@lit-labs/eleventy-plugin-lit Patch
@lit-labs/ssr Patch

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

@github-actions
Copy link
Contributor

github-actions bot commented Oct 20, 2023

📊 Tachometer Benchmark Results

Summary

nop-update

  • this-change, tip-of-tree, previous-release: unsure 🔍 -6% - +6% (-1.22ms - +1.15ms)
    this-change vs tip-of-tree

render

  • this-change: 88.96ms - 93.00ms
  • this-change, tip-of-tree, previous-release: unsure 🔍 -3% - +6% (-1.03ms - +2.46ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -4% - +3% (-2.47ms - +1.81ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -5% - +1% (-3.04ms - +0.57ms)
    this-change vs tip-of-tree

update

  • this-change: 984.76ms - 1004.08ms
  • this-change, tip-of-tree, previous-release: unsure 🔍 -6% - +3% (-4.21ms - +2.57ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -4% - +2% (-6.06ms - +2.46ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -2% - +1% (-20.49ms - +12.56ms)
    this-change vs tip-of-tree

update-reflect

  • this-change: 973.51ms - 995.47ms
  • this-change, tip-of-tree, previous-release: unsure 🔍 -1% - +2% (-14.85ms - +20.73ms)
    this-change vs tip-of-tree

Results

this-change

render

VersionAvg timevs
88.96ms - 93.00ms-

update

VersionAvg timevs
984.76ms - 1004.08ms-

update-reflect

VersionAvg timevs
973.51ms - 995.47ms-
this-change, tip-of-tree, previous-release

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
37.78ms - 40.57ms-unsure 🔍
-3% - +6%
-1.03ms - +2.46ms
unsure 🔍
-0% - +10%
-0.00ms - +3.54ms
tip-of-tree
tip-of-tree
37.41ms - 39.52msunsure 🔍
-6% - +3%
-2.46ms - +1.03ms
-unsure 🔍
-1% - +7%
-0.46ms - +2.57ms
previous-release
previous-release
36.32ms - 38.50msunsure 🔍
-9% - -0%
-3.54ms - +0.00ms
unsure 🔍
-7% - +1%
-2.57ms - +0.46ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
72.55ms - 77.54ms-unsure 🔍
-6% - +3%
-4.21ms - +2.57ms
unsure 🔍
-4% - +4%
-3.33ms - +2.68ms
tip-of-tree
tip-of-tree
73.58ms - 78.15msunsure 🔍
-3% - +6%
-2.57ms - +4.21ms
-unsure 🔍
-3% - +4%
-2.34ms - +3.33ms
previous-release
previous-release
73.69ms - 77.04msunsure 🔍
-4% - +4%
-2.68ms - +3.33ms
unsure 🔍
-4% - +3%
-3.33ms - +2.34ms
-

nop-update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
17.84ms - 19.85ms-unsure 🔍
-6% - +6%
-1.22ms - +1.15ms
unsure 🔍
-7% - +5%
-1.43ms - +0.87ms
tip-of-tree
tip-of-tree
18.26ms - 19.50msunsure 🔍
-6% - +6%
-1.15ms - +1.22ms
-unsure 🔍
-6% - +3%
-1.08ms - +0.58ms
previous-release
previous-release
18.57ms - 19.69msunsure 🔍
-5% - +8%
-0.87ms - +1.43ms
unsure 🔍
-3% - +6%
-0.58ms - +1.08ms
-
this-change, tip-of-tree, previous-release

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
61.76ms - 65.13ms-unsure 🔍
-4% - +3%
-2.47ms - +1.81ms
unsure 🔍
-3% - +3%
-2.01ms - +2.03ms
tip-of-tree
tip-of-tree
62.46ms - 65.09msunsure 🔍
-3% - +4%
-1.81ms - +2.47ms
-unsure 🔍
-2% - +3%
-1.39ms - +2.07ms
previous-release
previous-release
62.31ms - 64.56msunsure 🔍
-3% - +3%
-2.03ms - +2.01ms
unsure 🔍
-3% - +2%
-2.07ms - +1.39ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
133.62ms - 139.40ms-unsure 🔍
-4% - +2%
-6.06ms - +2.46ms
unsure 🔍
-3% - +3%
-4.33ms - +3.74ms
tip-of-tree
tip-of-tree
135.18ms - 141.44msunsure 🔍
-2% - +4%
-2.46ms - +6.06ms
-unsure 🔍
-2% - +4%
-2.71ms - +5.71ms
previous-release
previous-release
133.99ms - 139.63msunsure 🔍
-3% - +3%
-3.74ms - +4.33ms
unsure 🔍
-4% - +2%
-5.71ms - +2.71ms
-
this-change, tip-of-tree, previous-release

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
64.24ms - 66.72ms-unsure 🔍
-5% - +1%
-3.04ms - +0.57ms
unsure 🔍
-4% - +2%
-2.35ms - +1.28ms
tip-of-tree
tip-of-tree
65.41ms - 68.03msunsure 🔍
-1% - +5%
-0.57ms - +3.04ms
-unsure 🔍
-2% - +4%
-1.16ms - +2.56ms
previous-release
previous-release
64.69ms - 67.34msunsure 🔍
-2% - +4%
-1.28ms - +2.35ms
unsure 🔍
-4% - +2%
-2.56ms - +1.16ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
986.47ms - 1011.62ms-unsure 🔍
-2% - +1%
-20.49ms - +12.56ms
unsure 🔍
-1% - +2%
-14.16ms - +18.90ms
tip-of-tree
tip-of-tree
992.29ms - 1013.73msunsure 🔍
-1% - +2%
-12.56ms - +20.49ms
-unsure 🔍
-1% - +2%
-8.83ms - +21.50ms
previous-release
previous-release
985.95ms - 1007.40msunsure 🔍
-2% - +1%
-18.90ms - +14.16ms
unsure 🔍
-2% - +1%
-21.50ms - +8.83ms
-

update-reflect

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
1001.62ms - 1024.59ms-unsure 🔍
-1% - +2%
-14.85ms - +20.73ms
unsure 🔍
-2% - +2%
-16.60ms - +16.64ms
tip-of-tree
tip-of-tree
996.57ms - 1023.75msunsure 🔍
-2% - +1%
-20.73ms - +14.85ms
-unsure 🔍
-2% - +1%
-21.06ms - +15.21ms
previous-release
previous-release
1001.07ms - 1025.10msunsure 🔍
-2% - +2%
-16.64ms - +16.60ms
unsure 🔍
-2% - +2%
-15.21ms - +21.06ms
-

tachometer-reporter-action v2 for Benchmarks

@github-actions
Copy link
Contributor

The size of lit-html.js and lit-core.min.js are as expected.

Copy link
Collaborator

@justinfagnani justinfagnani left a comment

Choose a reason for hiding this comment

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

Awesome work!

@AndrewJakubowicz AndrewJakubowicz changed the title [ssr] fix ModuleLoader failing with multiple concurrent entrypoints [labs/ssr] fix ModuleLoader failing with multiple concurrent entrypoints Oct 20, 2023
Copy link
Member

@augustjk augustjk left a comment

Choose a reason for hiding this comment

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

Nice!

@AndrewJakubowicz AndrewJakubowicz enabled auto-merge (squash) October 21, 2023 00:10
@AndrewJakubowicz AndrewJakubowicz merged commit f9c3659 into main Oct 21, 2023
@AndrewJakubowicz AndrewJakubowicz deleted the fix-concurrent-entrypoints branch October 21, 2023 00:34
This was referenced Oct 27, 2023
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.

[labs/ssr] ModuleLoader linker fails with multiple concurrent entrypoints

3 participants