patricklx / ember-vite-hmr

6 stars 1 forks source link

Can't make new state persistance HMR work #80

Closed evoactivity closed 2 months ago

evoactivity commented 2 months ago

I've updated my app blueprint to latest and bumped the embroider deps.

I've configured the babel config as in the readme.

I have components on my application.hbs file and when I update a component I see hmr replaces application.hbs instead of the component I updated, so all state is lost.

In a different route (/test) where I have wrapped my component with a parent component, when I update my component I see this error

Uncaught (in promise) Error: Expected a dynamic component definition, but received an object or function that did not have a component manager associated with it. The dynamic invocation was <this.curried> or {{this.curried}}, and the incorrect definition is the value at the path this.curried, which was: CurriedValue

Reproduction is here https://github.com/evoactivity/ember-vite-hmr-state-persistence

patricklx commented 2 months ago

mm, i have to take a look. one issue was the transforms setting in babel config: must be transforms: [...templateCompatSupport(), hotAstProcessor.transform]

but there are more issues

evoactivity commented 2 months ago

I don't think that has fixed it.

I moved the transform to come after templateCompatSupport and updated the addon, deleted node_modules and my lock file.

Now on the application homepage, I see the component render for a brief moment then disappears with the same error as earlier.

Uncaught (in promise) Error: Expected a dynamic component definition, but received an object or function that did not have a component manager associated with it. The dynamic invocation was <this.curried> or {{this.curried}}, and the incorrect definition is the value at the path this.curried, which was: CurriedValue

I've pushed those changes to my repro repo.

patricklx commented 2 months ago

i checked it, there is a bug with embroider vite that it does not use the optmized dep sometimes. I thought I had fixed it by doing this: https://github.com/patricklx/ember-vite-hmr/blob/main/src/instance-initializers/setup-hmr-manager.ts#L7 but apparently it does not work always. if you add

import { curry } from '@glimmer/runtime';
console.log(curry);

to your app.js it starts working

patricklx commented 2 months ago

ah, I get it now why it passes in local testing. im using a linked package to ember-vite-hmr and that does not get optmized, but it's deps get optimized. Which is why it works here...

evoactivity commented 2 months ago

Adding the curry import makes it work :)

Nice job on this btw, it's so nice to have HMR be viable in ember now!