Skip to content

Commit

Permalink
fix: avoid template instance mutation in HMR mode (#1862)
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey authored Oct 26, 2022
1 parent 8909ef3 commit 30e0ea4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .changeset/soft-cups-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"marko": patch
"@marko/compiler": patch
"@marko/translator-default": patch
---

Avoid mutating component instance in HMR mode. (Improves support in tags api preview)
8 changes: 4 additions & 4 deletions packages/marko/src/runtime/vdom/hot-reload.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var updateManager = require("../components/update-manager");
var createTemplate = runtime.t;
var createComponent = registry.___createComponent;
var registered = {};
var instancesByType = {};
var queue;

runtime.t = function (typeName) {
Expand All @@ -16,7 +17,7 @@ runtime.t = function (typeName) {

var renderFn;
var template = (registered[typeName] = createTemplate(typeName));
var instances = (template.___instances = []);
var instances = (instancesByType[typeName] = []);
Object.defineProperty(template, "_", {
get: function () {
return renderFn && proxyRenderer;
Expand Down Expand Up @@ -75,11 +76,10 @@ runtime.t = function (typeName) {
};

registry.___createComponent = function (typeName, id) {
var template = registered[typeName];
var instances = instancesByType[typeName];
var instance = createComponent(typeName, id);

if (template) {
var instances = template.___instances;
if (instances) {
instances.push(instance);
instance.once("destroy", function () {
if (!instance.___hmrDestroyed) {
Expand Down

0 comments on commit 30e0ea4

Please sign in to comment.