-
Notifications
You must be signed in to change notification settings - Fork 314
Description
Description
Currently, watched file recompilation of a file with a type provider fails to update the provided type definitions when the underlying data changes. The type definition is generated only on initial compile and remains stuck in its initial state for the duration of the webpack-dev-server session. This results in compiler errors during recompile in watch mode, and requires a stop and restart to pick up the changes.
Any chance this could be made to work, either by the formal TP invalidation mechanism, or else some kind of reset option on the internal compiler to recompile from scratch instead of whatever internal TP state it is currently holding on to?
Repro code
Here is a repro project, using a modified Fable.JsonProvider with invalidation and logging added.
Repro steps:
Clone repo: https://github.com/zanaptak/TestFableTypeProvider.git
Run: dotnet build ./TypeProvider (because App.fsproj has a file path reference to the debug version of this assembly)
Run: npm install
Run (Fable 2): npm start
Run (Fable 3): dotnet tool restore
Run (Fable 3): dotnet fable watch App --run webpack-dev-server
Open App folder in VS Code (recommend disabling background services in ionide settings and restarting first, to reduce log noise)
Observe: IDE and Fable compile both work, no type errors
In schema.json, change foo1 to foo2 (this triggers invalidation of the TP)
In App.fs, if error not already appeared, make an inconsequential edit to trigger a type check
Observe: IDE should recognize the TP invalidation, regen the type definition, and show error on the old json.foo1 property name
In App.fs, change json.foo1 to json.foo2, and save
Observe: IDE is happy with new property name
Observe: Fable watched file recompilation fails. The new code change is picked up, but the TP was not refreshed, and the new property name does not exist on the stale type definition.
Check the TypeProvider.log file in the App dir and observe differences in how both processes behave:
Observe: IDE supports invalidation, resulting in incrementing TP instances [0], [1]… in the log.
Observe: Fable uses a single TP instance [0]. It appears to call into the TP when the recompile happens. We have no caching in the TP so we return an updated type definition, but Fable seems to be ignoring it and keeping the stale type.
Expected and actual results
Expected: A change to TP underlying data recompiles successfully in watch mode.
Actual: Recompilation fails, requires restart of webpack-dev-server.
Related information
- Fable version:
2.10.23.0.0-nagareyama-rc-004 - Operating system: Windows 10