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

Every other hot reload fails with browser exception #26

Open
kwesterfeld opened this issue Jun 8, 2017 · 12 comments
Open

Every other hot reload fails with browser exception #26

kwesterfeld opened this issue Jun 8, 2017 · 12 comments

Comments

@kwesterfeld
Copy link

I am using systemjs-tools backend, which is nicely sending updates. However, after the first reload event, my application only updates on every other change. The browser always gets an exception like this when it doesn't work:

systemjs-hmr.js:12430 Error: Fetch error: 404 
  Instantiating https://localhost:8183/smc/app/main.js - bundle/components.js
  Loading https://localhost:8183/smc/app/main.js - bundle/components.js
    at system.src.js:1458
    at <anonymous>

As you can see, the app/main.js is being triggered to reload, but it is containing my application's bundled dependencies for some reason on every other change.

I have configured jspm bundling with config injection such that that my application is bundled in two parts:

  • all app dependencies go in "components.js" to avoid rebundling cost of all dependencies
  • all app code bundled to "dependencies.js" to trigger reload in systemjs-tools

I turned on debug for systemjs-hmr, and noticed in the browser the difference between the two events being processed:


:8183/smc/jspm_packages/npm/[email protected]/dist/systemjs-hmr.js:1796 systemjs-hmr:log dependency tree purged, reimporting entries +1ms 
Array(1)
0
:
"app/main.js - bundle/components.js"
length
:
1
__proto__
:
Array(0)
systemjs-hmr.js:1796 systemjs-hmr:log dependency tree purged, reimporting entries +1ms 
(3) ["https://localhost:8183/smc/app/main.js", "https://localhost:8183/smc/bundle/dependencies.js", "https://localhost:8183/smc/bundle/components.js"]
0
:
"https://localhost:8183/smc/app/main.js"
1
:
"https://localhost:8183/smc/bundle/dependencies.js"
2
:
"https://localhost:8183/smc/bundle/components.js"
length
:
3
__proto__
:
Array(0)

image

@kwesterfeld
Copy link
Author

@alexisvincent any updates on this one?

@alexisvincent
Copy link
Owner

@kwesterfeld Not yet, sorry.

I picked up an extra major this year and my module count is at the university system maximum. Struggling to meet even those demands, and everything else is suffering at the moment. I finish the degree in just over 2 months, so I'm not going to look at anything until then.

But I'll be able to give this, and the rest of my OSS projects (systemjs-hot-reloader, systemjs-tools, systemjs-config-builder, systemjs-unpkg-loader) some much needed attention as soon as thats over.

I do have quite a few changes sitting on disk though aimed at fixing this and a number of issues in the systems-hot-reloader project. Will make everything more stable, and provide a better testing story.

@kwesterfeld
Copy link
Author

kwesterfeld commented Sep 14, 2017 via email

@alexisvincent
Copy link
Owner

@kwesterfeld Thanks for all your help so far. It really is appreciated.

Yeah, it's quite fundamental to the project. Essentially systemjs-hot-reloader is unusable until this gets fixed. Im surprised not more people are complaining...

@alexisvincent
Copy link
Owner

Hold on, this bug isn't what I thought it was.

@alexisvincent
Copy link
Owner

Ok, I think I understand where the problem is. I'm guessing you have "app/main.js - bundle/components.js" set as an entry in your systemjs-tools config? systemjs-tools then passes that to systemjs-hot-reloader so that you don't have to redefine that behavior. So "app/main.js - bundle/components.js" is getting passed to systemjs-hot-reloader everytime a change happens. And then SystemJS tries to load it causing an issue.

You need to just have app/main.js as a logical entry. It's an array so that you can have lazy loaded app entry places.

You also don't need to use jspm to bundle... Just use systemjs-tools with the watch flag. The entries should be cached. I know it takes long when source mappings are there, since those aren't nicely cached by systemjs-builder.

There are two things that could be done to make bundling faster. Improving the builder so that it caches source maps (better) or upgrading systemjs-tools so that it understands the bundling directives (shouldn't be hard).

Let me know if this sorts things out for you.

@alexisvincent
Copy link
Owner

In the future I want to be able to submit arbitrary build flags to the systemjs-tools and have it perform the operation on the fly. Actually this would completely solve the issue...

If we have an option to generate arbitrary dependencies instead of just dependencies.js, then you can replace the entry in the config with a url to systems-tools and this whole thing will work automatically...

@kwesterfeld
Copy link
Author

kwesterfeld commented Sep 14, 2017 via email

@alexisvincent
Copy link
Owner

@kwesterfeld Do you have the systemjs-tools cache enabled? Should make loading 6s always, even after a restart of the process. Crazy large size though... I understand why theres a wait.

Got you for the vendor thing. Wanting to implement something like this automatically with analysis of module dependencies and monitoring which deps have quick release cycles.

@alexisvincent
Copy link
Owner

Also planning on switching to static file serving that works for dev and production, which will mean you won't pay the cost of bundling more then you need to.

The preemptive bundling feature will also make your life nicer one I've added the required changes to the builder project.

See

@kwesterfeld
Copy link
Author

kwesterfeld commented Sep 16, 2017 via email

@alexisvincent
Copy link
Owner

@kwesterfeld You can add an option that specifies the bundle trigger.

https://github.com/alexisvincent/systemjs-tools/blob/master/lib/handlers.js#L22

But what I want to do is actually be able to intercept arbitrary bundle arithmetic (like what is passed to systemjs-builder) and then just do that.

Note you can also provide your own handlers to systemjs-tools that does arbitrary logic. I provide a number of handlers that you can use to make your ones. By default it uses the default handler. Check that out if you want to see how its done

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

No branches or pull requests

2 participants