Skip to content

Auto import dependencies #2494

@WTbohdano

Description

@WTbohdano
  • SystemJS Version: 6.8.3 | 6.15.1
  • Which library are you using?
    • system.js
    • s.js
    • system-node.cjs
  • Which extras are you using?
    • AMD extra
    • Named Exports
    • Named Register
    • Transform
    • Use Default
    • Global
    • Dynamic Import Maps
  • Are you using any custom hooks? No

Question

I have an issue with auto import logic. I have storybook which is configured to a library type system. It automatically loads the systemjs like output bundle.
SystemJS has document readyState check, in case loading it would add module to a autoImportCandidates. Later on its used in a instantiate logic, so it skip module load. Because of it, getRegister is not executed and last register is not reset. It leads to a wrong dependency resolution of the first dependency of a module.

Example:

System.register(['react', 'react-dom'],  () => {...})

First module dependency react has a dependency ['react', 'react-dom']

Workaround

Im hacking auto import logic, manually calling getRegister to reset lastRegister

const SystemJSPrototype = System.constructor.prototype;
const register = SystemJSPrototype.register;

SystemJSPrototype.register = function() {
  register.apply(this, arguments);

  if (document.readyState === 'loading') {
    SystemJSPrototype.getRegister();
  }
}

Sumarry

Is it expected behavior ?
I guess lastRegister should be reseted on auto imported modules as well. It could be done right once autoImportCandidates is reseted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions