@astrojs/solid-js
Advanced tools
Comparing version 0.0.0-cloudcannon-fix-20230306211609 to 0.0.0-dupicate-content-entry-improved-message-20231220220040
@@ -1,2 +0,1 @@ | ||
import { sharedConfig } from "solid-js"; | ||
import { createComponent, hydrate, render } from "solid-js/web"; | ||
@@ -9,21 +8,31 @@ var client_default = (element) => (Component, props, slotted, { client }) => { | ||
return; | ||
const fn = client === "only" ? render : hydrate; | ||
const boostrap = client === "only" ? render : hydrate; | ||
let slot; | ||
let _slots = {}; | ||
if (Object.keys(slotted).length > 0) { | ||
if (sharedConfig.context) { | ||
element.querySelectorAll("astro-slot").forEach((slot) => { | ||
_slots[slot.getAttribute("name") || "default"] = slot.cloneNode(true); | ||
if (client !== "only") { | ||
const iterator = document.createTreeWalker(element, NodeFilter.SHOW_ELEMENT, (node) => { | ||
if (node === element) | ||
return NodeFilter.FILTER_SKIP; | ||
if (node.nodeName === "ASTRO-SLOT") | ||
return NodeFilter.FILTER_ACCEPT; | ||
if (node.nodeName === "ASTRO-ISLAND") | ||
return NodeFilter.FILTER_REJECT; | ||
return NodeFilter.FILTER_SKIP; | ||
}); | ||
} else { | ||
for (const [key, value] of Object.entries(slotted)) { | ||
_slots[key] = document.createElement("astro-slot"); | ||
if (key !== "default") | ||
_slots[key].setAttribute("name", key); | ||
_slots[key].innerHTML = value; | ||
} | ||
while (slot = iterator.nextNode()) | ||
_slots[slot.getAttribute("name") || "default"] = slot; | ||
} | ||
for (const [key, value] of Object.entries(slotted)) { | ||
if (_slots[key]) | ||
continue; | ||
_slots[key] = document.createElement("astro-slot"); | ||
if (key !== "default") | ||
_slots[key].setAttribute("name", key); | ||
_slots[key].innerHTML = value; | ||
} | ||
} | ||
const { default: children, ...slots } = _slots; | ||
const renderId = element.dataset.solidRenderId; | ||
fn( | ||
const dispose = boostrap( | ||
() => createComponent(Component, { | ||
@@ -39,2 +48,3 @@ ...props, | ||
); | ||
element.addEventListener("astro:unmount", () => dispose(), { once: true }); | ||
}; | ||
@@ -41,0 +51,0 @@ export { |
@@ -1,3 +0,3 @@ | ||
import type { RendererContext } from './types'; | ||
declare type Context = { | ||
import type { RendererContext } from './types.js'; | ||
type Context = { | ||
id: string; | ||
@@ -4,0 +4,0 @@ c: number; |
import type { AstroIntegration } from 'astro'; | ||
export default function (): AstroIntegration; | ||
import { type Options as ViteSolidPluginOptions } from 'vite-plugin-solid'; | ||
export type Options = Pick<ViteSolidPluginOptions, 'include' | 'exclude'>; | ||
export default function (opts?: Options): AstroIntegration; |
@@ -1,24 +0,5 @@ | ||
import { getSolidPkgsConfig } from "./dependencies.js"; | ||
function getRenderer() { | ||
return { | ||
name: "@astrojs/solid-js", | ||
clientEntrypoint: "@astrojs/solid-js/client.js", | ||
serverEntrypoint: "@astrojs/solid-js/server.js", | ||
jsxImportSource: "solid-js", | ||
jsxTransformOptions: async ({ ssr }) => { | ||
const [{ default: solid }] = await Promise.all([import("babel-preset-solid")]); | ||
const options = { | ||
presets: [solid({}, { generate: ssr ? "ssr" : "dom", hydratable: true })], | ||
plugins: [], | ||
inputSourceMap: false | ||
}; | ||
return options; | ||
} | ||
}; | ||
} | ||
async function getViteConfiguration(isDev, astroConfig) { | ||
import solid, {} from "vite-plugin-solid"; | ||
async function getViteConfiguration(isDev, { include, exclude } = {}) { | ||
const nestedDeps = ["solid-js", "solid-js/web", "solid-js/store", "solid-js/html", "solid-js/h"]; | ||
const solidPkgsConfig = await getSolidPkgsConfig(!isDev, astroConfig); | ||
return { | ||
esbuild: { include: /\.ts$/ }, | ||
resolve: { | ||
@@ -30,19 +11,42 @@ conditions: ["solid", ...isDev ? ["development"] : []], | ||
optimizeDeps: { | ||
include: [...nestedDeps, ...solidPkgsConfig.optimizeDeps.include], | ||
exclude: ["@astrojs/solid-js/server.js", ...solidPkgsConfig.optimizeDeps.exclude] | ||
include: [...nestedDeps], | ||
exclude: ["@astrojs/solid-js/server.js"] | ||
}, | ||
plugins: [ | ||
solid({ include, exclude, dev: isDev, ssr: true }), | ||
{ | ||
name: "@astrojs/solid:config-overrides", | ||
enforce: "post", | ||
config() { | ||
return { | ||
esbuild: { | ||
// To support using alongside other JSX frameworks, still let | ||
// esbuild compile stuff. Solid goes first anyways. | ||
include: /\.(m?ts|[jt]sx)$/ | ||
} | ||
}; | ||
} | ||
} | ||
], | ||
ssr: { | ||
target: "node", | ||
external: ["babel-preset-solid", ...solidPkgsConfig.ssr.external], | ||
noExternal: ["solid-js", ...solidPkgsConfig.ssr.noExternal] | ||
external: ["babel-preset-solid"] | ||
} | ||
}; | ||
} | ||
function src_default() { | ||
function getRenderer() { | ||
return { | ||
name: "@astrojs/solid-js", | ||
clientEntrypoint: "@astrojs/solid-js/client.js", | ||
serverEntrypoint: "@astrojs/solid-js/server.js" | ||
}; | ||
} | ||
function src_default(opts = {}) { | ||
return { | ||
name: "@astrojs/solid-js", | ||
hooks: { | ||
"astro:config:setup": async ({ command, addRenderer, updateConfig, config }) => { | ||
"astro:config:setup": async ({ command, addRenderer, updateConfig }) => { | ||
addRenderer(getRenderer()); | ||
updateConfig({ vite: await getViteConfiguration(command === "dev", config) }); | ||
updateConfig({ | ||
vite: await getViteConfiguration(command === "dev", opts) | ||
}); | ||
} | ||
@@ -49,0 +53,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import type { RendererContext } from './types'; | ||
import type { RendererContext } from './types.js'; | ||
declare function check(this: RendererContext, Component: any, props: Record<string, any>, children: any): boolean; | ||
@@ -12,3 +12,4 @@ declare function renderToStaticMarkup(this: RendererContext, Component: any, props: Record<string, any>, { default: children, ...slotted }: any, metadata?: undefined | Record<string, any>): { | ||
renderToStaticMarkup: typeof renderToStaticMarkup; | ||
supportsAstroStaticSlot: boolean; | ||
}; | ||
export default _default; |
@@ -7,2 +7,4 @@ import { createComponent, renderToString, ssr } from "solid-js/web"; | ||
return false; | ||
if (Component.name === "QwikComponent") | ||
return false; | ||
const { html } = renderToStaticMarkup.call(this, Component, props, children); | ||
@@ -12,3 +14,5 @@ return typeof html === "string"; | ||
function renderToStaticMarkup(Component, props, { default: children, ...slotted }, metadata) { | ||
const renderId = (metadata == null ? void 0 : metadata.hydrate) ? incrementId(getContext(this.result)) : ""; | ||
const renderId = metadata?.hydrate ? incrementId(getContext(this.result)) : ""; | ||
const needsHydrate = metadata?.astroStaticSlot ? !!metadata.hydrate : true; | ||
const tagName = needsHydrate ? "astro-slot" : "astro-static-slot"; | ||
const html = renderToString( | ||
@@ -19,3 +23,3 @@ () => { | ||
const name = slotName(key); | ||
slots[name] = ssr(`<astro-slot name="${name}">${value}</astro-slot>`); | ||
slots[name] = ssr(`<${tagName} name="${name}">${value}</${tagName}>`); | ||
} | ||
@@ -25,3 +29,4 @@ const newProps = { | ||
...slots, | ||
children: children != null ? ssr(`<astro-slot>${children}</astro-slot>`) : children | ||
// In Solid SSR mode, `ssr` creates the expected structure for `children`. | ||
children: children != null ? ssr(`<${tagName}>${children}</${tagName}>`) : children | ||
}; | ||
@@ -43,3 +48,4 @@ return createComponent(Component, newProps); | ||
check, | ||
renderToStaticMarkup | ||
renderToStaticMarkup, | ||
supportsAstroStaticSlot: true | ||
}; | ||
@@ -46,0 +52,0 @@ export { |
import type { SSRResult } from 'astro'; | ||
export declare type RendererContext = { | ||
export type RendererContext = { | ||
result: SSRResult; | ||
}; |
{ | ||
"name": "@astrojs/solid-js", | ||
"version": "0.0.0-cloudcannon-fix-20230306211609", | ||
"version": "0.0.0-dupicate-content-entry-improved-message-20231220220040", | ||
"description": "Use Solid components within Astro", | ||
@@ -29,10 +29,12 @@ "type": "module", | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"dependencies": { | ||
"babel-preset-solid": "^1.4.2", | ||
"vitefu": "^0.2.4" | ||
"vite-plugin-solid": "^2.7.0" | ||
}, | ||
"devDependencies": { | ||
"astro": "0.0.0-cloudcannon-fix-20230306211609", | ||
"astro-scripts": "0.0.0-cloudcannon-fix-20230306211609", | ||
"solid-js": "^1.5.1" | ||
"solid-js": "^1.8.5", | ||
"astro": "0.0.0-dupicate-content-entry-improved-message-20231220220040", | ||
"astro-scripts": "0.0.14" | ||
}, | ||
@@ -43,4 +45,7 @@ "peerDependencies": { | ||
"engines": { | ||
"node": ">=16.12.0" | ||
"node": ">=18.14.1" | ||
}, | ||
"publishConfig": { | ||
"provenance": true | ||
}, | ||
"scripts": { | ||
@@ -47,0 +52,0 @@ "build": "astro-scripts build \"src/**/*.ts\" && tsc", |
@@ -12,2 +12,3 @@ # @astrojs/solid-js 💙 | ||
Astro includes a CLI tool for adding first party integrations: `astro add`. This command will: | ||
1. (Optionally) Install all necessary dependencies and peer dependencies | ||
@@ -45,12 +46,12 @@ 2. (Also optionally) Update your `astro.config.*` file to apply this integration | ||
__`astro.config.mjs`__ | ||
```diff lang="js" "solid()" | ||
// astro.config.mjs | ||
import { defineConfig } from 'astro/config'; | ||
+ import solid from '@astrojs/solid-js'; | ||
```js ins={2} "solid()" | ||
import { defineConfig } from 'astro/config'; | ||
import solid from '@astrojs/solid-js'; | ||
export default defineConfig({ | ||
// ... | ||
integrations: [solid()], | ||
}); | ||
export default defineConfig({ | ||
// ... | ||
integrations: [solid()], | ||
// ^^^^^^^ | ||
}); | ||
``` | ||
@@ -61,2 +62,3 @@ | ||
To use your first SolidJS component in Astro, head to our [UI framework documentation][astro-ui-frameworks]. You'll explore: | ||
- 📦 how framework components are loaded, | ||
@@ -66,2 +68,38 @@ - 💧 client-side hydration options, and | ||
## Options | ||
### Combining multiple JSX frameworks | ||
When you are using multiple JSX frameworks (React, Preact, Solid) in the same project, Astro needs to determine which JSX framework-specific transformations should be used for each of your components. If you have only added one JSX framework integration to your project, no extra configuration is needed. | ||
Use the `include` (required) and `exclude` (optional) configuration options to specify which files belong to which framework. Provide an array of files and/or folders to `include` for each framework you are using. Wildcards may be used to include multiple file paths. | ||
We recommend placing common framework components in the same folder (e.g. `/components/react/` and `/components/solid/`) to make specifying your includes easier, but this is not required: | ||
```js | ||
// astro.config.mjs | ||
import { defineConfig } from 'astro/config'; | ||
import preact from '@astrojs/preact'; | ||
import react from '@astrojs/react'; | ||
import svelte from '@astrojs/svelte'; | ||
import vue from '@astrojs/vue'; | ||
import solid from '@astrojs/solid-js'; | ||
export default defineConfig({ | ||
// Enable many frameworks to support all different kinds of components. | ||
// No `include` is needed if you are only using a single JSX framework! | ||
integrations: [ | ||
preact({ | ||
include: ['**/preact/*'], | ||
}), | ||
react({ | ||
include: ['**/react/*'], | ||
}), | ||
solid({ | ||
include: ['**/solid/*'], | ||
}), | ||
], | ||
}); | ||
``` | ||
## Troubleshooting | ||
@@ -68,0 +106,0 @@ |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
2
113
15578
13
214
1
+ Addedvite-plugin-solid@^2.7.0
+ Added@babel/compat-data@7.26.8(transitive)
+ Added@babel/core@7.26.8(transitive)
+ Added@babel/generator@7.26.8(transitive)
+ Added@babel/parser@7.26.8(transitive)
+ Added@babel/template@7.26.8(transitive)
+ Added@babel/traverse@7.26.8(transitive)
+ Added@babel/types@7.26.8(transitive)
+ Added@esbuild/aix-ppc64@0.24.2(transitive)
+ Added@esbuild/android-arm@0.24.2(transitive)
+ Added@esbuild/android-arm64@0.24.2(transitive)
+ Added@esbuild/android-x64@0.24.2(transitive)
+ Added@esbuild/darwin-arm64@0.24.2(transitive)
+ Added@esbuild/darwin-x64@0.24.2(transitive)
+ Added@esbuild/freebsd-arm64@0.24.2(transitive)
+ Added@esbuild/freebsd-x64@0.24.2(transitive)
+ Added@esbuild/linux-arm@0.24.2(transitive)
+ Added@esbuild/linux-arm64@0.24.2(transitive)
+ Added@esbuild/linux-ia32@0.24.2(transitive)
+ Added@esbuild/linux-loong64@0.24.2(transitive)
+ Added@esbuild/linux-mips64el@0.24.2(transitive)
+ Added@esbuild/linux-ppc64@0.24.2(transitive)
+ Added@esbuild/linux-riscv64@0.24.2(transitive)
+ Added@esbuild/linux-s390x@0.24.2(transitive)
+ Added@esbuild/linux-x64@0.24.2(transitive)
+ Added@esbuild/netbsd-arm64@0.24.2(transitive)
+ Added@esbuild/netbsd-x64@0.24.2(transitive)
+ Added@esbuild/openbsd-arm64@0.24.2(transitive)
+ Added@esbuild/openbsd-x64@0.24.2(transitive)
+ Added@esbuild/sunos-x64@0.24.2(transitive)
+ Added@esbuild/win32-arm64@0.24.2(transitive)
+ Added@esbuild/win32-ia32@0.24.2(transitive)
+ Added@esbuild/win32-x64@0.24.2(transitive)
+ Added@rollup/rollup-android-arm-eabi@4.34.6(transitive)
+ Added@rollup/rollup-android-arm64@4.34.6(transitive)
+ Added@rollup/rollup-darwin-arm64@4.34.6(transitive)
+ Added@rollup/rollup-darwin-x64@4.34.6(transitive)
+ Added@rollup/rollup-freebsd-arm64@4.34.6(transitive)
+ Added@rollup/rollup-freebsd-x64@4.34.6(transitive)
+ Added@rollup/rollup-linux-arm-gnueabihf@4.34.6(transitive)
+ Added@rollup/rollup-linux-arm-musleabihf@4.34.6(transitive)
+ Added@rollup/rollup-linux-arm64-gnu@4.34.6(transitive)
+ Added@rollup/rollup-linux-arm64-musl@4.34.6(transitive)
+ Added@rollup/rollup-linux-loongarch64-gnu@4.34.6(transitive)
+ Added@rollup/rollup-linux-powerpc64le-gnu@4.34.6(transitive)
+ Added@rollup/rollup-linux-riscv64-gnu@4.34.6(transitive)
+ Added@rollup/rollup-linux-s390x-gnu@4.34.6(transitive)
+ Added@rollup/rollup-linux-x64-gnu@4.34.6(transitive)
+ Added@rollup/rollup-linux-x64-musl@4.34.6(transitive)
+ Added@rollup/rollup-win32-arm64-msvc@4.34.6(transitive)
+ Added@rollup/rollup-win32-ia32-msvc@4.34.6(transitive)
+ Added@rollup/rollup-win32-x64-msvc@4.34.6(transitive)
+ Added@types/babel__core@7.20.5(transitive)
+ Added@types/babel__generator@7.6.8(transitive)
+ Added@types/babel__template@7.4.4(transitive)
+ Added@types/babel__traverse@7.20.6(transitive)
+ Added@types/estree@1.0.6(transitive)
+ Added@types/gensync@1.0.4(transitive)
+ Addedcaniuse-lite@1.0.30001699(transitive)
+ Addedelectron-to-chromium@1.5.97(transitive)
+ Addedesbuild@0.24.2(transitive)
+ Addedfsevents@2.3.3(transitive)
+ Addedis-what@4.1.16(transitive)
+ Addedmerge-anything@5.1.7(transitive)
+ Addednanoid@3.3.8(transitive)
+ Addedpostcss@8.5.2(transitive)
+ Addedrollup@4.34.6(transitive)
+ Addedsolid-refresh@0.6.3(transitive)
+ Addedsource-map-js@1.2.1(transitive)
+ Addedvite@6.1.0(transitive)
+ Addedvite-plugin-solid@2.11.1(transitive)
+ Addedvitefu@1.0.5(transitive)
- Removedbabel-preset-solid@^1.4.2
- Removedvitefu@^0.2.4
- Removed@babel/compat-data@7.26.5(transitive)
- Removed@babel/core@7.26.7(transitive)
- Removed@babel/generator@7.26.5(transitive)
- Removed@babel/parser@7.26.7(transitive)
- Removed@babel/template@7.25.9(transitive)
- Removed@babel/traverse@7.26.7(transitive)
- Removed@babel/types@7.26.7(transitive)
- Removedcaniuse-lite@1.0.30001698(transitive)
- Removedelectron-to-chromium@1.5.96(transitive)
- Removedvitefu@0.2.5(transitive)