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

Skip to content

Conversation

@internettrans
Copy link
Collaborator

@internettrans internettrans commented May 5, 2021

See #2327 (comment) and #2293. cc @anhallbe who found the problem.

System core expects to never be called with the string name as the first argument, but named-register does so. The reason the tests pass and named-register works for some people is that named-register overrides getRegister to retrieve from registerRegistry for named registers. However, when that doesn't happen, the lastRegister in system core is just incorrect!

@github-actions
Copy link

github-actions bot commented May 5, 2021

File size impact

Merging issue-2293 into master will impact 1 file in 1 group.

browser (0/2)

No impact on files in browser group.

node (0/1)

No impact on files in node group.

extras (1/8)
File raw gzip brotli Event
dist/extras/named-register.min.js -7 (854) +1 (419) -3 (350) modified
Total size impact -7 (854) +1 (419) -3 (350)
Generated by file size impact during size-impact#821687886

});
}
return register.apply(this, arguments);
return register.apply(deps, declare);
Copy link

@anhallbe anhallbe May 5, 2021

Choose a reason for hiding this comment

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

This should probably be:

return register.apply(this, [deps, declare]);

I don't know how to reproduce the issue in the unit tests, but here's a repro with the above fix:

https://codesandbox.io/s/broken-sun-c3xjm?file=/index.html

See the named-register-fixed.js

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah good catch, I thought I had tested this but now that I see the problem I wonder why my testing wouldn't have noticed that it wasn't correct.

I've updated it now.

Copy link
Member

@guybedford guybedford left a comment

Choose a reason for hiding this comment

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

Thanks for catching this! Is it possible to get a test to cover this case?

@internettrans
Copy link
Collaborator Author

internettrans commented May 7, 2021

Is it possible to get a test to cover this case?

Not without some reworking of the tests - currently the amd.js extra is executed before the named-register extra, which alters behavior in such a way that the test would pass both with and without the new code.

@internettrans internettrans merged commit d9788de into master May 12, 2021
@internettrans internettrans deleted the issue-2293 branch May 12, 2021 21:08
@internettrans
Copy link
Collaborator Author

@restjohn
Copy link

restjohn commented May 25, 2021

FYI, this appears to be a breaking change with respect to previous behavior. After updating to 6.9.0, System.import() now returns the last named register module instead of the actual module fetched from the URL. For example, at initialization, I do

const lib1Exports = ...
const lib2Exports = ...
System.register('lib1', [],  _export => {
  return {
    execute: () => {
      _export(lib1Exports)
      // deliberate undefined return because returning something here screws up systemjs
      return void(0)
    }
  }
})
System.register('lib2', [], _export => {
  return {
    execute: () => {
      _export(lib2Exports)
      return void(0)
    }
  }
})

Then later

const lib3 = await System.import('/libs/lib3.umd.js')
!!lib3.lib2Member // true

The above worked as expected with version 6.8.x and the named-register/amd extras.

See this sandbox that demonstrates the issue. You'll need to comment/uncomment the script elements as necessary to switch between SystemJS versions. https://codesandbox.io/s/epic-goldstine-r1qio?file=/index.html

dumganhar pushed a commit to dumganhar/systemjs that referenced this pull request Jan 26, 2024
…js#2293. (systemjs#2329)

* Fix named-register.js - omit name from register call. Resolves systemjs#2293.

* Feedback
dumganhar added a commit to cocos/systemjs that referenced this pull request Jan 26, 2024
…js#2293. (systemjs#2329) (#1)

* Fix named-register.js - omit name from register call. Resolves systemjs#2293.

* Feedback

Co-authored-by: Joel Denning <[email protected]>
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.

5 participants