Skip to content

public directory is not copied when building twice with write: false and then write: true #22305

Description

@hi-ogawa

Describe the bug

@vitejs/plugin-rsc uses building same environment instance twice, such as following:

import { defineConfig } from 'vite';

export default defineConfig({
  builder: {
    async buildApp(builder) {
      builder.environments.client.config.build.write = false;
      await builder.build(builder.environments.client);
      builder.environments.client.config.build.write = true;
      await builder.build(builder.environments.client);
    },
  },
});

Since Vite 8.0.9, this doesn't copy public directory on second build.

This specific behavior only hits unconventional rsc examples, so this isn't critical, but just reporting it here if anyone has an idea where this is expected, whether this should be avoided, etc.

This behavior change was found in vitejs/vite-plugin-react#1198

Reproduction

https://stackblitz.com/edit/vitejs-vite-2gdu7zbt?file=vite.config.ts

Steps to reproduce

  • open stackblitz
  • run vite build
  • see there's no dist/favicon.svg

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 22.22.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.8.2 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    vite: ^8.0.10 => 8.0.10

Used Package Manager

npm

Logs

No response

Validations

Activity

  1. added theissue type on Apr 23, 2026
  2. sapphi-red commented on Apr 23, 2026

    @sapphi-red
    Member

    Ah, this is probably because the copy sets a flag once the renderStart is called regardless of whether the copy actually happened.

    if (rendered.has(this.environment)) {
    return
    }
    rendered.add(this.environment)

    Probably we can move rendered.add(this.environment) inside the if (config.build.write).

  3. locked and limited conversation to collaborators on Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: buildp2-edge-caseBug, but has workaround or limited in scope (priority)

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions