-
-
Notifications
You must be signed in to change notification settings - Fork 115
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
Add basic HMR integration to Blaze #313
Conversation
I'm excited about this! When I created a new app using this from the beginning, it worked wonderfully.
EDIT: thanks Zodern, I guess that was it, I restarted and cannot reproduce the issue. |
@namenotrequired did you restart Meteor after adding the |
I updated an older app to 2.0-rc.3 and get errors on Firefox 83. I also deactivated the browser-policy package to be sure nothing blocks.
With Chromium 85 I get:
Could it be because I use CoffeeScript? |
@softwarerero could you please create a reproduction? |
Thank you for adding HMR support to Blaze! I'm very excited to get this working. On Safari, Chrome and Firefox on macOS Big Sur, I'm seeing |
It doesn't work if Eventually I will change the integration to support it. Until then, I am using this code in one app that uses if (module.hot) {
let currentTemplate;
let currentRegions;
const oldRender = BlazeLayout.render;
BlazeLayout.render = function (template, regions) {
currentTemplate = template;
currentRegions = regions;
oldRender.call(this, template, regions);
};
const oldMigrateTemplate = Template._migrateTemplate;
Template._migrateTemplate = function () {
BlazeLayout.reset();
oldMigrateTemplate.apply(this, arguments);
BlazeLayout._render(currentTemplate, currentRegions);
};
} |
@zodern I am using |
I am also using I still get "Uncaught Error: Expected template rendered with Blaze.render" on the console but that seems to be only a cosmetic issue. My test code is here: https://github.com/softwarerero/m2bt |
Hi, Blaze HMR You can try this integration in apps using Meteor 2+ by running:
To also use HMR for javascript files that use the Template api, run
|
With the second beta there are two implementations of applying updates during HMR. By default it uses a simple one that replaces all root views when a template is modified. This is slow and loses all template instance state, but should work reliably. This is similar to how the first beta worked. The second one is used when the Some other changes:
|
We are merging this PR to #323 We are close to finish this new release (2.4) |
You can try this integration in apps using Meteor 2 by running:
To also use HMR for javascript files that use the Template api, run
Spacebar Templates
When HMR is enabled, spacebar templates are automatically updated with HMR. To apply changes, all of the root views are destroyed and recreated (no template instance state is preserved). If this causes problems for some apps, we can provide a way to disable it.
When the
blaze-hot
package is added, it instead only updates the blaze views for the modified templates. This is much faster, and preserves state for parent and sibling templates. However, it might not be compatible with all frameworks built on Blaze and with code that accesses the DOM of children templates.JS files that use the Template API's to add helpers, event maps, and callbacks
The
blaze-hot
package is able to automatically update files that use the Template API's. There are two types of files that are automatically updated with HMR:meteor/templating
ormeteor/blaze
and it does not have any exportsThe
blaze-hot
package keeps track of helpers, callbacks, event maps, etc. that are added when a module is first ran. When the module is updated, it removes any helpers, callbacks, event maps, etc. the old version of the module added. Any that are added after the module is initially ran, such as inMeteor.startup
or in a callback are not tracked and automatically removed.When possible it tries to only update the Blaze views for the modified templates, without affecting parent or sibling views so their state can be preserved. In some cases it has to update parent views instead or update all root views, especially when modified templates use or are used as custom block tags.
When a file is updated, Meteor calls any dispose handlers for the old version, and then runs the new version. Depending on what else the file does (creating collections, Method stubs, Tracker autoruns outside of a Blaze template, etc.), it might not support having two versions of the file running in the app. In that case, you can either: