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

Fixes for named-register extra. #2352

Merged
merged 1 commit into from Aug 17, 2021
Merged

Fixes for named-register extra. #2352

merged 1 commit into from Aug 17, 2021

Conversation

joeldenning
Copy link
Collaborator

This resolves #2349. It fixes two bugs:

  1. When loading a bundle via System.import() with named registers, it is no longer possible for the first named register in the bundle to instantiate twice. Previously this was true, as the register array was instantiated once for the bundle of the module and once for the name it gave itself via a named register.
  2. The named-register extra now always returns the first named register, rather than sometimes the first named define and sometimes the last named register

Demonstration of the bugs:

  1. (todo)
  2. Last named register returned (script-load.js) and First named register returned (transform.js)

The changes I had to make to solve these bugs were more invasive than I was hoping for. It might be safest to release this is a new major version, as people are probably accidentally relying on the named-register extra to sometimes return the first named register and other times the last named register.

I'm open to all feedback on this one, as it was quite difficult and I tried several approaches before finding one that worked in all cases. The first bug is solved by creating a new namedRegisterAliases property on systemjs instances, to ensure that only one module is instantiated. The second bug is solved by switching from Promise.resolve to setTimeout, since the load event for <script> events seems to run after the Promise.resolve() executes.

Adding the url to the getRegister API was something I wanted to avoid, but ultimately was the least invasive approach I found that worked.

@guybedford I would appreciate your review on this one, if you're able to.

@github-actions
Copy link

File size impact

Merging issue-2349 into main will impact 5 files in 3 groups.

browser (2/2)
File raw gzip brotli Event
dist/s.min.js +3 (7,561) +4 (2,983) +2 (2,709) modified
dist/system.min.js +3 (11,850) +4 (4,569) +1 (4,118) modified
Total size impact +6 (19,411) +8 (7,552) +3 (6,827)
node (1/1)
File raw gzip brotli Event
dist/system-node.cjs +3 (201,509) -1 (52,168) -35 (43,821) modified
Total size impact +3 (201,509) -1 (52,168) -35 (43,821)
extras (2/8)
File raw gzip brotli Event
dist/extras/named-register.min.js +127 (981) +38 (457) +33 (383) modified
dist/extras/transform.min.js +1 (591) +2 (370) +1 (302) modified
Total size impact +128 (1,572) +40 (827) +34 (685)
Generated by file size impact during size-impact#1065086873

@joeldenning
Copy link
Collaborator Author

@guybedford do you have time to look at this one? If not, should I go ahead and merge?

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.

This looks great! Perhaps we can actually just make this a minor release, I would really prefer not to do a new major. If you think there is a very high risk of breakage, is there perhaps a way we can keep the old behaviour and have a flag for the new behaviour for the next major?

@guybedford
Copy link
Member

And sorry, this dropped off my notifications as SystemJS notifications bundle together for me here.

@joeldenning
Copy link
Collaborator Author

The named-register extra now always returns the first named register, rather than sometimes the first named define and sometimes the last named register

I think we could call this a bug fix rather than a breaking change? This was the part that I was thinking might be a breaking change for some, but only because they're accidentally relying on buggy behavior.

@guybedford
Copy link
Member

Ok yes, let's do it as a bug fix then.

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.

v6 loading module in importmap twice
2 participants