solid-start icon indicating copy to clipboard operation
solid-start copied to clipboard

[Bug?]: unplugin-macros doesn't work

Open huseeiin opened this issue 7 months ago • 3 comments

Duplicates

  • [x] I have searched the existing issues

Latest version

  • [x] I have tested the latest version

Current behavior 😯

lib/test.ts:

export function getRandom() {
  return Math.random();
}

export const buildTime = Date.now();

routes/test.ts:

import { buildTime, getRandom } from "../lib/test.ts" with { type: "macro" };

export function GET() {
  return getRandom();
}

console.log(buildTime);

when you go to /test you'll see a different value every time.

Expected behavior 🤔

its supposed to be the same value every time, since its a macro.

config:

import Macros from "unplugin-macros/vite";
import { defineConfig } from "@solidjs/start/config";

export default defineConfig({
  vite: {
    plugins: [Macros()],
  },
});

Steps to reproduce 🕹

i couldn't reproduce in vinxi. this bug is only in solidstart.

Context 🔦

No response

Your environment 🌎


huseeiin avatar Jul 10 '25 12:07 huseeiin

this is because of how api routes are imported under the hood by solid start, with a ?pick=GET (or ?pick=POST) query.

huseeiin avatar Jul 23 '25 08:07 huseeiin

Do you have suggestions how to handle this? I assume its uncompatible right now

brenelz avatar Aug 04 '25 02:08 brenelz

Do you have suggestions how to handle this? I assume its uncompatible right now

we need a way to import routes without a query. sveltekit does this. i don't know how tho

huseeiin avatar Aug 04 '25 07:08 huseeiin