Skip to content

fix(ssg): clean pages/ and app/ before webstudio build to avoid stale imports#10

Closed
vianmora wants to merge 12 commits into
mainfrom
fix/stale-pages-after-rename
Closed

fix(ssg): clean pages/ and app/ before webstudio build to avoid stale imports#10
vianmora wants to merge 12 commits into
mainfrom
fix/stale-pages-after-rename

Conversation

@vianmora

@vianmora vianmora commented May 7, 2026

Copy link
Copy Markdown
Contributor

Problem

When a page is renamed or deleted in the Webstudio builder, webstudio build --template ssg updates app/__generated__/ (removes the old data file, adds the new one) but leaves orphaned +Page.tsx files in pages/.

Vite then fails during the static build because the stale +Page.tsx still imports the now-deleted __generated__ file:

Could not resolve "../../../../app/__generated__/[templates].[copy-1].[chartegraphique]._index"
from "pages/templates/copy-1/chartegraphique/+Page.tsx"

Fix

Delete pages/ and app/ before each webstudio build --template ssg so the CLI always starts from a clean state. The node_modules/ directory is preserved to avoid reinstalling dependencies unnecessarily.

Test plan

  • Rename a page in the builder, publish → build should succeed
  • Delete a page in the builder, publish → build should succeed
  • Normal publish (no renames) → build should succeed
  • First publish on a new domain → build should succeed

🤖 Generated with Claude Code

vianmora and others added 12 commits April 27, 2026 18:21
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…e template

DOCKER_PORT_BASE env var (default 6000), dockerDomainPort map, allocateDockerPort,
and DOCKER_SITE_DOCKERFILE multi-stage template (adapted from @m8jj for
react-router-docker output: no .next/cache, no public/).

No behaviour change — pipelines and HTTP handler untouched.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
sync → build --template docker → write Dockerfile → docker build once
→ stop/rm/run container → prune → state.json → register all hostnames
in ssrHostPort so the existing proxy serves Docker sites without changes.

One image per domain, one container, all custom domains routed to same port.
Uses DOCKER_BUILDKIT=1 to enable cache mounts from DOCKER_SITE_DOCKERFILE.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add stopDockerForDomain helper (stop/rm container, clean ssrHostPort +
dockerDomainPort). Wire transitions in all three pipelines:
  ssg/ssr → docker : clean up stale output / kill subprocess before build
  docker  → ssg    : stop container + clear proxy entries
  docker  → ssr    : stop container + force clean node_modules install

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Extend restoreSsrProcesses to handle mode: "docker" state.json entries.
Checks if the container is running via docker inspect; restarts it if not.
Reconstructs dockerDomainPort and ssrHostPort so the proxy routes correctly
after a publisher container restart.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add "docker" to accepted buildMode values and dispatch to publishBuildDocker.
Update file-level JSDoc. Warn at startup if Docker socket is not accessible.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add workflow, infra requirement (docker socket), port range, and
BuildKit optimization notes. Add DOCKER_PORT_BASE to env var table.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Remove the subprocess-based publishBuildSsr and installSsrDeps.
The Docker pipeline (previously publishBuildDocker) is now the SSR
implementation — same buildMode: "ssr" sent by the builder, no API change.

Existing state.json files with mode: "ssr" are still restored at startup
via the legacy subprocess path (restoreSsrProcesses); they migrate to Docker
on next republish via the ssr→docker transition handler.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Replace host-port mapping with Docker network routing:
- Add DOCKER_NETWORK env var — shared network between publisher and site containers
- Replace dockerDomainPort/allocateDockerPort with dockerHostContainer map (hostname → containerName)
- docker run: remove -p PORT:3000, add --network=${DOCKER_NETWORK}
- Proxy: check dockerHostContainer first → proxy to containerName:3000
  Legacy SSR subprocess path (ssrHostPort → 127.0.0.1) kept for existing installs
- Warn at startup if Docker socket or DOCKER_NETWORK is missing

Without this fix, the proxy returned 502 for all Docker SSR sites because
127.0.0.1:PORT is not reachable from inside the publisher container.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
apk add docker-cli installs the Docker client without the buildx plugin.
With DOCKER_BUILDKIT=1, modern Docker CLI requires buildx — without it,
docker build fails with 'buildx component is missing or broken'.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The react-router-docker template generates a package.json with a React
canary version (18.3.0-canary-...). npm strict semver rejects canary
versions as satisfying >=18 peer deps, causing ERESOLVE on every build.

--legacy-peer-deps bypasses this check without affecting runtime behavior.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… imports

When a page is renamed or deleted in the builder, webstudio build --template ssg
updates __generated__/ but leaves orphaned +Page.tsx files in pages/. Vite then
fails to resolve the broken import from the stale page file.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@vianmora vianmora changed the base branch from feat/buildmode-docker to main May 7, 2026 11:19
@vianmora

vianmora commented May 7, 2026

Copy link
Copy Markdown
Contributor Author

Replaced by #11

@vianmora vianmora closed this May 7, 2026
@vianmora vianmora deleted the fix/stale-pages-after-rename branch May 17, 2026 16:00
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