fix(include): apply patches on refresh - #57
Open
tdwhere123 wants to merge 4 commits into
Open
Conversation
refresh() reloaded the file and updated the tree without applyPatches, so HMR config reloads dropped disabled/config overrides. Reuse the init path and await the tree update.
Drop the constructor internal/update hunk: applyPatches mutates nested entries, so a same-path update could insert twice. refresh() is the HMR path; await loader quiescence in the regression instead of sleeps.
refresh() re-runs applyPatches on a baked file. Pushing the patch object let ensureId stamp an id back onto Include config, so the next apply appended a second same-id row. Copy the entry and skip if that id or name is already in the target list.
Insert overlays now stamp a stable id on the patch item so a re-read updates the same entry instead of remove+create. refresh() is the disk snapshot path: drop in-flight writes, ignore tree.write() until it returns, and queue overlapping calls.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Include[Service.init]appliespatchesbeforeroot.update().refresh()feedsthis.datastraight into the tree.read()always replacesthis.datawith the file contents. HMR config reloads callinclude.refresh(), so adisabled/ config override / insert patch is dropped whenever the file changes and has not been baked back to disk (readonly files never are).A writable refresh that recreates an insert (new anonymous id) goes through
EntryGroup.remove→fiber.dispose()→tree.write()and dumpsroot.data(overlays) over the user's file. The next real edit then double-appliesinsert.main[Service.init]applyPatchesthenawait root.updaterefresh()after a file changeawait root.update; nowrite()internal/updateroot.update(this.data)Change
Reuse the init sequence in
refresh():await this.root.update(this.applyPatches([...this.data!])).applyPatchesinsert copies each entry afterensureIdon the patch item, and skips if that id is already in the tree or the target list already has that name.refresh()treats the file as source of truth: overlapping calls are queued, in-flightwriteFiletimers are dropped, andwrite()is ignored untilroot.updatereturns.The same-path
internal/updatehandler still callsthis.root.update(this.data!). Nestedinsertstill mutates shared entry objects; that path stays deferred until a clone-then-patch exists.writeFile/stop/ the debounce queue implementation are otherwise untouched (#47).Regression coverage
packages/include/tests/patch.spec.ts:innervia patch, rewrite the file,refresh(), entry stays disabled./extra-plugin,write()bake, rewrite the file, refresh, one extra row./extra-plugin, comment-only rewrite, refresh: file bytes stay the comment (no bake), extra id unchangedValidation
yarn lintyarn test include/patch— 13 tests passed