Skip to content

Commit

Permalink
Merge branch 'main' into fix/preact-signals
Browse files Browse the repository at this point in the history
  • Loading branch information
ph1p committed Aug 25, 2024
2 parents b9fa93a + 6fcaab8 commit 0f4f08e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/fuzzy-falcons-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Marks internal `vite-plugin-fileurl` plugin with `enforce: 'pre'`
2 changes: 1 addition & 1 deletion packages/astro/src/core/create-vite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export async function createVite(
astroPrefetch({ settings }),
astroTransitions({ settings }),
astroDevToolbar({ settings, logger }),
vitePluginFileURL({}),
vitePluginFileURL(),
astroInternationalization({ settings }),
settings.config.experimental.serverIslands && vitePluginServerIslands({ settings }),
astroContainer(),
Expand Down
3 changes: 2 additions & 1 deletion packages/astro/src/vite-plugin-fileurl/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { Plugin as VitePlugin } from 'vite';

export default function vitePluginFileURL({}): VitePlugin {
export default function vitePluginFileURL(): VitePlugin {
return {
name: 'astro:vite-plugin-file-url',
enforce: 'pre',
resolveId(source, importer) {
if (source.startsWith('file://')) {
const rest = source.slice(7);
Expand Down
6 changes: 3 additions & 3 deletions packages/integrations/preact/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ export default (element: HTMLElement) =>
let signalsRaw = element.dataset.preactSignals;
if (signalsRaw) {
const { signal } = await import('@preact/signals');
let signals: Record<string, string | { id: string; i: number }[]> = JSON.parse(
let signals: Record<string, string | [string, number][]> = JSON.parse(
element.dataset.preactSignals!,
);
for (const [propName, signalId] of Object.entries(signals)) {
if (Array.isArray(signalId)) {
signalId.forEach(({ id, i }) => {
const [valueOfSignal, indexInProps] = props[propName][i];
signalId.forEach(([id, indexInPropsArray]) => {
const [valueOfSignal, indexInProps] = props[propName][indexInPropsArray];
if (!sharedSignalMap.has(id)) {
const signalValue = signal(valueOfSignal);
sharedSignalMap.set(id, signalValue);
Expand Down
2 changes: 1 addition & 1 deletion packages/integrations/preact/src/signals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export function serializeSignals(
props[key] = props[key].map((v: SignalLike, i: number) =>
i === index ? [signal.peek(), i] : v,
);

map.set(key, [...((map.get(key) || []) as []), [signal, index]]);

signals[key] = [...((signals[key] || []) as []), [getSignalId(ctx, signal), index]];
}
});
Expand Down

0 comments on commit 0f4f08e

Please sign in to comment.