Repository navigation
Conversation
The Solid compiler leaves the templates of $ServerOnly elements out of the client bundle, since hydration reuses the server-rendered DOM. Hot module replacement re-runs the component on the client and needs them, so the first edit to a component whose root uses $ServerOnly threw "template is not a function". - Add solidPlugins, which passes omitServerOnlyTemplates: false to vite-plugin-solid in dev, under the same condition vite-plugin-solid uses to enable hot reloading. Production builds still leave the templates out, and a value set by the user is kept. - Update the lockfile to babel-preset-solid 1.9.15, which brings babel-plugin-jsx-dom-expressions 0.40.11. The option was added in 0.40.10. 1.9.15 still accepts solid-js 1.9.15. Fixes #1930. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
✅ Deploy Preview for solid-start-landing-page ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
🦋 Changeset detectedLatest commit: 6179bd6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
commit: |
Contributor
|
I had a potential fix for this here. Is this a more complete one? |
Member
Author
|
Closing in favor of solidjs/solid-vite-plugin#362, which makes the same fix in |
Member
Author
|
@brenelz I wasn't aware of it. It supercedes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1930. The 1.x fix is #2341.
In dev, editing a component whose root element uses
$ServerOnlythrowsTypeError: template is not a functionon the first hot update, and the component's content disappears from the page.Cause
In hydratable builds, the Solid compiler leaves the templates of
$ServerOnlyelements out of the client bundle. Hydration does not need them, since it reuses the server-rendered DOM. Hot module replacement re-runs the component on the client, though, and there is no template to create it from. birkskyum reduced this to a plainvite-plugin-solidreproduction in solidjs/solid-vite-plugin#308, which is still open.Fix
babel-plugin-jsx-dom-expressions0.40.10 added anomitServerOnlyTemplatesoption, andbabel-preset-solidpasses it through.config/solid.tsexportssolidPlugins. It handsvite-plugin-solidits ownsolidoptions object and setsomitServerOnlyTemplates: falsefromconfigResolved, using the same conditionvite-plugin-soliduses to enable hot reloading (command === "serve",mode !== "production",hot !== false).vite-plugin-solidreads these options on every transform, so the value applies to the whole dev session. The option only affects client (DOM) output, so SSR output is unchanged.omitServerOnlyTemplatesthemselves, their value is kept.babel-preset-solid1.9.12 → 1.9.15, which bringsbabel-plugin-jsx-dom-expressions0.40.7 → 0.40.11. I picked 1.9.15 rather than 1.9.16 because 1.9.16 requiressolid-js ^1.9.16and the repo is on 1.9.15. Those two packages are the only lockfile changes.Testing
solid.spec.tsruns the realvite-plugin-solidtransform throughsolidPluginson a$ServerOnlycomponent. It checks that the client dev build keeps the template, the production build leaves it out, a user value oftrueis kept, andhot: falseleaves it out. The dev-build case fails without the fix.basicfixture in a browser, route with a$ServerOnlyroot: before, the first edit threwtemplate is not a functionand the content disappeared. After, the edit applies with no errors. With the user settingomitServerOnlyTemplates: true, the error comes back, as expected.$ServerOnlytext is in the server output and in none of the 7 client JS files. As a control, forcingomitServerOnlyTemplates: falseeverywhere puts it in a client file, so the check does detect a leak.@solidjs/start:test:ci(217 tests),typecheck,validate-importsandbuildpass.apps/tests: unit tests, Playwright e2e (42) and bundled-dev e2e (42) pass.🤖 Generated with Claude Code