Repository navigation
Commit 58998de
fix(md): run client scripts in builds without an .island. file (#681)
A client script in a Markdown page ran in dev but not after a production
build, unless a file with `.island.` in its name existed under `pages/`.
Without one, `dist/client/.vite/manifest.json` had no
`virtual:void-md-client` entry, so the script never loaded.
The `config` hook in `voidMarkdown()` added that entry only when
`hasMdFilesWithScript(pagesDir) && hasIslandFiles(pagesDir)` was true.
`hasIslandFiles` only read file names under `pages/`, so:
- A Markdown page that imports an island did not count. The island
hydrated, but the rest of the script did not run.
- A `.island.` file outside `pages/` did not count.
- Any matching name counted, even an empty `pages/_x.island.txt`.
## Fix
The entry is now added when a page that the build keeps has client code.
The check uses the same file list and `extractScript()` as
`scanMdPages()`, so it agrees with what the entry loads.
This also replaces the `/^<script\b/m` check. It matched a script with
only island imports, a `<script>` in a code block and a `.dev` page,
none of which has client code in a build. With a `.island.` file
present, those apps built a 0-byte `md-client` chunk that their pages
with JavaScript loaded. They now get no entry.
The guide already describes this behavior, so the docs do not change.
## Tests
- `packages/md/test/integration/client-script-build.test.ts` (new):
builds a React app with no `.island.` file under `pages/` and opens it
in Chromium. A script-only page and a page that also imports an island
both run their scripts, the island responds to a click, and a page
without client code ships no `<script>`. On `main` it fails because the
manifest has no `virtual:void-md-client`.
- `packages/md/test/unit/plugin-source-dir.test.ts`: covers which pages
add the entry. Four cases fail on `main`, and four fail if only
`hasIslandFiles` is removed.
## Verification
- `vp test run`: 765 files pass, 1 skipped (15,607 tests pass, 29
skipped).
- `vp run check`: 33/33 pass.
- By hand on React, Vue, Svelte and Solid, with `vp build`, `vp preview`
(Cloudflare target) and Chromium: client scripts run, and an app without
client code gets no `md-client` entry. Svelte and Solid used an absolute
island import because of the first issue below, and the Solid island did
not respond because of the second.
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>1 parent 2ecbb7f commit 58998de
3 files changed
Lines changed: 145 additions & 44 deletions
File tree
- packages/md
- src
- test
- integration
- unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
75 | 68 | | |
76 | 69 | | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
83 | 75 | | |
84 | | - | |
85 | | - | |
86 | 76 | | |
87 | 77 | | |
88 | 78 | | |
| |||
114 | 104 | | |
115 | 105 | | |
116 | 106 | | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
| 107 | + | |
123 | 108 | | |
124 | 109 | | |
125 | 110 | | |
| |||
156 | 141 | | |
157 | 142 | | |
158 | 143 | | |
159 | | - | |
| 144 | + | |
160 | 145 | | |
161 | 146 | | |
162 | 147 | | |
| |||
166 | 151 | | |
167 | 152 | | |
168 | 153 | | |
169 | | - | |
| 154 | + | |
170 | 155 | | |
171 | 156 | | |
172 | 157 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
| 80 | + | |
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
124 | | - | |
| 124 | + | |
125 | 125 | | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
134 | 130 | | |
135 | 131 | | |
136 | | - | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
137 | 135 | | |
138 | | - | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
139 | 150 | | |
140 | 151 | | |
141 | 152 | | |
| |||
147 | 158 | | |
148 | 159 | | |
149 | 160 | | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
150 | 184 | | |
0 commit comments