Fix client validation flickers - #451
Merged
Merged
Conversation
🦋 Changeset detectedLatest commit: 4a78351 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Val UI sync engine to prevent a brief UI “flicker” in fs mode when publish() succeeds and the patch chain is dropped, by baking the currently optimistic (patched) value into serverSources before patch state is reset.
Changes:
- In
ValSyncEngine.publish()(fs mode), bake the patched source value intoserverSourcesbefore clearing patch state, then invalidate affected module sources. - Add a regression test covering the fs-mode publish flicker, plus a fake
/saveimplementation in the test harness to model fs behavior. - Add a changeset for
@valbuild/uidescribing the flicker fix.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
packages/ui/spa/ValSyncEngine.ts |
Bakes patched values into serverSources in fs mode during publish to avoid reverting to the unpatched base between patch deletion and next sources refresh. |
packages/ui/spa/ValSyncEngine.test.ts |
Adds a regression test for the publish flicker and extends the fake API with an fs-mode /save behavior. |
examples/next/val.config.ts |
Enables a hard-coded project in the example config (appears unrelated to the sync-engine flicker fix). |
examples/next/app/blogs/[blog]/page.val.ts |
Changes example blog title content (appears unrelated to the sync-engine flicker fix). |
.changeset/fix-save-content-flicker.md |
Documents the UI patch release for the flicker fix. |
Comments suppressed due to low confidence (1)
packages/ui/spa/ValSyncEngine.ts:3143
- In fs mode
publish()setsthis.globalServerSidePatchIds = [], but it never callsinvalidateGlobalServerSidePatchIds(). IfgetGlobalServerSidePatchIdsSnapshot()has been read previously, the cached snapshot (and any listeners) can remain stale even though the underlying IDs were cleared.
// In fs mode we delete all patch ids, so we start fresh
this.globalServerSidePatchIds = [];
console.debug("Deleting all patch ids");
}
- publish() now invalidates the globalServerSidePatchIds snapshot when it empties it in fs mode, so the Save button transitions enabled -> disabled cleanly instead of briefly flicking back to enabled until the next stat/sync. - The fake /save and /sources/~ in SyncEngineTester now filter `file` ops before applyPatch (which rejects them with "Cannot apply a file patch here"), mirroring applySourceFilePatches in ValOps. Previously a patch containing file ops silently failed to persist in the fake fs-mode save. postSave also honors req.body.patchIds and reports apply failures as a 400 (like the real endpoint, which bails before writing sources or deleting patches) instead of swallowing them. - Revert the unrelated blog title change in the Next.js example. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
No description provided.