summaryrefslogtreecommitdiff
path: root/packages/integrations/solid
diff options
context:
space:
mode:
Diffstat (limited to 'packages/integrations/solid')
-rw-r--r--packages/integrations/solid/CHANGELOG.md6
-rw-r--r--packages/integrations/solid/package.json2
-rw-r--r--packages/integrations/solid/src/client.ts67
3 files changed, 48 insertions, 27 deletions
diff --git a/packages/integrations/solid/CHANGELOG.md b/packages/integrations/solid/CHANGELOG.md
index bc1d135d0..9f69e7e2f 100644
--- a/packages/integrations/solid/CHANGELOG.md
+++ b/packages/integrations/solid/CHANGELOG.md
@@ -1,5 +1,11 @@
# @astrojs/solid-js
+## 4.4.2
+
+### Patch Changes
+
+- [#11998](https://github.com/withastro/astro/pull/11998) [`082f450`](https://github.com/withastro/astro/commit/082f45094471d52e55c55d3291f541306d9388b1) Thanks [@johannesspohr](https://github.com/johannesspohr)! - Fix view transition state persistence
+
## 4.4.1
### Patch Changes
diff --git a/packages/integrations/solid/package.json b/packages/integrations/solid/package.json
index 5320cc57e..7a3cb6e15 100644
--- a/packages/integrations/solid/package.json
+++ b/packages/integrations/solid/package.json
@@ -1,6 +1,6 @@
{
"name": "@astrojs/solid-js",
- "version": "4.4.1",
+ "version": "4.4.2",
"description": "Use Solid components within Astro",
"type": "module",
"types": "./dist/index.d.ts",
diff --git a/packages/integrations/solid/src/client.ts b/packages/integrations/solid/src/client.ts
index a47c5310d..f2020bb56 100644
--- a/packages/integrations/solid/src/client.ts
+++ b/packages/integrations/solid/src/client.ts
@@ -1,10 +1,12 @@
import { Suspense } from 'solid-js';
+import { createStore, reconcile } from 'solid-js/store';
import { createComponent, hydrate, render } from 'solid-js/web';
+const alreadyInitializedElements = new WeakMap<Element, any>();
+
export default (element: HTMLElement) =>
(Component: any, props: any, slotted: any, { client }: { client: string }) => {
if (!element.hasAttribute('ssr')) return;
-
const isHydrate = client !== 'only';
const bootstrap = isHydrate ? hydrate : render;
@@ -32,31 +34,44 @@ export default (element: HTMLElement) =>
const { default: children, ...slots } = _slots;
const renderId = element.dataset.solidRenderId;
+ if (alreadyInitializedElements.has(element)) {
+ // update the mounted component
+ alreadyInitializedElements.get(element)!(
+ // reconcile will make sure to apply as little updates as possible, and also remove missing values w/o breaking reactivity
+ reconcile({
+ ...props,
+ ...slots,
+ children,
+ }),
+ );
+ } else {
+ const [store, setStore] = createStore({
+ ...props,
+ ...slots,
+ children,
+ });
+ // store the function to update the current mounted component
+ alreadyInitializedElements.set(element, setStore);
- const dispose = bootstrap(
- () => {
- const inner = () =>
- createComponent(Component, {
- ...props,
- ...slots,
- children,
- });
+ const dispose = bootstrap(
+ () => {
+ const inner = () => createComponent(Component, store);
- if (isHydrate) {
- return createComponent(Suspense, {
- get children() {
- return inner();
- },
- });
- } else {
- return inner();
- }
- },
- element,
- {
- renderId,
- },
- );
-
- element.addEventListener('astro:unmount', () => dispose(), { once: true });
+ if (isHydrate) {
+ return createComponent(Suspense, {
+ get children() {
+ return inner();
+ },
+ });
+ } else {
+ return inner();
+ }
+ },
+ element,
+ {
+ renderId,
+ },
+ );
+ element.addEventListener('astro:unmount', () => dispose(), { once: true });
+ }
};