Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug?]: Same plugin instance being passed to multiple routers can cause problems #1277

Closed
2 tasks done
edivados opened this issue Jan 23, 2024 · 3 comments
Closed
2 tasks done
Labels
bug Something isn't working

Comments

@edivados
Copy link
Contributor

edivados commented Jan 23, 2024

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

Vite plugins some times use factory functions and keep state inside the function scope to pass it between hooks. Solid-Start passing the same plugin instaces to multiple routers can cause unexpected problems.

Currently this is avoidable by using a function for plugins instead of an array.

Expected behavior 🤔

Not to pass the same instance to multiple routers.

Steps to reproduce 🕹

Open in StackBlitz

Steps:

  1. pnpm create solid
  2. select basic/ts/ssr
  3. add the vite.config below
  4. pnpm run build

Watch the items count increase between router builds.

import { defineConfig } from "@solidjs/start/config";

const itemsPlugin = () => {
  const items = [];

  return {
    name: "items-plugin",
    generateBundle() {
      items.push(1);
    },
    closeBundle() {
      console.log("Items: ", items.length);
    }
  }
}

export default defineConfig({
  plugins: [itemsPlugin()]
});

Context 🔦

Came across this on nksaraf/vinxi#108 (comment) with unplugin-imagemin where one problem (3rd point) is caused by this.

Your environment 🌎

No response

@ryansolid
Copy link
Member

ryansolid commented Feb 21, 2024

What would you prefer, We always force the function, or have it just be an option?

@edivados
Copy link
Contributor Author

Unless there is a reason not to, I would default to always using a function so I don't have to think about this problem.

@ryansolid
Copy link
Member

I think 0.6.0 basically solves this now with there being vite as a function. So closing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants