Skip to content

feat(site-editor): remember the preview device size and editing mode across reloads - #8031

Merged
pedrofrxncx merged 1 commit into
mainfrom
feat/site-editor-persist-preview-state
Oct 16, 2026
Merged

pedrofrxncx merged 1 commit into
mainfrom
feat/site-editor-persist-preview-state

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

What is this contribution about?

Reloading the Site Editor reset the preview to desktop and to the default editing mode, so a user previewing on mobile, or who had closed Blocks, lost that state on every refresh.

The Preview device size (desktop / mobile / tablet) and the editing mode (preview / visual / blocks) now persist in localStorage per project, through the existing useLocalStorage hook. The editing mode stays unset until the user picks one, so a first visit still gets the gated default (Blocks on desktop when content editing is on). Stored values outside the known set fall back to the defaults, and a restored Blocks mode on a project where Blocks is gated still renders the plain preview through resolveEffectivePreviewEditingMode.

The Preview / Content / Code switch is already route-owned (/site-editor, /site-editor/content, /site-editor/code), so a refresh keeps it; nothing changes there.

How did you verify your code works?

  • apps/web: tsc --noEmit passes.
  • bun test apps/web/src/components/sandbox/preview: 238 pass, 0 fail.
  • bun run fmt, bun run lint and bun run knip pass. The full bun test run reported failures in unrelated suites (e.g. plugins/ban-cross-tree-imports.test.ts failing on empty oxlint JSON output); that file passes when run on its own, both with and without this change.
  • Not yet verified in the browser.

Screenshots/Demonstration

Pending.

How to Test

  1. Open a project's Site Editor on desktop.
  2. Toggle the device to mobile and switch Blocks off (or turn Visual on), then reload.
  3. The preview comes back on mobile with the same editing mode.
  4. Open another project: it keeps its own settings, and a project never touched starts on desktop with the default mode.

Review Checklist

  • PR title is clear and descriptive
  • Changes are tested and working
  • Documentation is updated (if needed)
  • No breaking changes

Summary by cubic

Reloading the Site Editor no longer resets the preview to desktop or to the default editing mode. Device size (desktop/mobile/tablet) and editing mode (preview/visual/blocks) now persist in localStorage per project through the existing useLocalStorage hook, so a mobile preview or a closed Blocks panel survives a refresh.

  • The editing mode stays unset until the user picks one, so a first visit still gets the gated default (Blocks on desktop when content editing is on).
  • Stored values outside the known set fall back to the defaults, and a restored Blocks mode on a project where Blocks is gated still renders the plain preview through resolveEffectivePreviewEditingMode.
  • The Preview/Content/Code switch is route-owned and unchanged.

Written for commit d226048. Summary will update on new commits.

View guided diff Turn on auto-fix

@pedrofrxncx
pedrofrxncx marked this pull request as ready for review October 16, 2026 16:01
@pedrofrxncx
pedrofrxncx enabled auto-merge (squash) October 16, 2026 16:01
@pedrofrxncx
pedrofrxncx merged commit 2b9c3d2 into main Oct 16, 2026
24 checks passed
@pedrofrxncx
pedrofrxncx deleted the feat/site-editor-persist-preview-state branch October 16, 2026 16:08
decocms Bot pushed a commit that referenced this pull request Oct 16, 2026
PR: #8031 feat(site-editor): remember the preview device size and editing mode across reloads
Bump type: minor

- decocms (apps/api/package.json): 4.494.0 -> 4.495.0

Deploy-Scope: web
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.

1 participant