Skip to content

Fix client validation flickers - #451

Merged
freekh merged 2 commits into
mainfrom
fix-client-validation-related-flickers
Jul 28, 2026
Merged

Fix client validation flickers#451
freekh merged 2 commits into
mainfrom
fix-client-validation-related-flickers

Conversation

@freekh

@freekh freekh commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@freekh
freekh requested a review from Copilot June 27, 2026 08:02
@changeset-bot

changeset-bot Bot commented Jun 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4a78351

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@valbuild/ui Patch
@valbuild/server Patch
@valbuild/next Patch
@valbuild/react Patch
@valbuild/cli Patch

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 into serverSources before clearing patch state, then invalidate affected module sources.
  • Add a regression test covering the fs-mode publish flicker, plus a fake /save implementation in the test harness to model fs behavior.
  • Add a changeset for @valbuild/ui describing 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() sets this.globalServerSidePatchIds = [], but it never calls invalidateGlobalServerSidePatchIds(). If getGlobalServerSidePatchIdsSnapshot() 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");
        }

Comment thread packages/ui/spa/ValSyncEngine.test.ts
Comment thread examples/next/val.config.ts
Comment thread examples/next/app/blogs/[blog]/page.val.ts
- 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>
@freekh
freekh merged commit e700926 into main Jul 28, 2026
6 checks passed
@freekh
freekh deleted the fix-client-validation-related-flickers branch July 28, 2026 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants