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

[Feature?]: Add an option to disable lazy loading in <FileRoutes /> #1575

Open
2 tasks done
huseeiin opened this issue Jul 3, 2024 · 3 comments
Open
2 tasks done
Labels
enhancement New feature or request

Comments

@huseeiin
Copy link
Contributor

huseeiin commented Jul 3, 2024

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Summary 💡

currently, FileRoutes lazy-loades all routes by default which is sometimes undesired.

Adding a sync option (that is false by default) or a async option to enable lazy loading (that is false by default) to FileRoutes to disable lazy loading all routes will fix that.

even better, this could be decided for each route separately.

Examples 🌈

a workaround is using custom <Route />s instead of using <FileRoutes />:

import { MetaProvider, Title } from "@solidjs/meta";
import { Route, Router } from "@solidjs/router";
import { Suspense } from "solid-js";
import Home from "./routes";
import About from "./routes/about";
import { get } from "./lib/api";
import NotFound from "./routes/[...404]";

export default function App() {
  return (
    <Router
      root={(props) => (
        <MetaProvider>
          <Title>SolidStart - Basic</Title>
          <a href="/">Index</a>
          <a href="/about">About</a>
          <Suspense>{props.children}</Suspense>
        </MetaProvider>
      )}
    >
      <Route path="/" component={Home} />
      <Route load={() => get()} path="/about" component={About} />
      <Route path="*404" component={NotFound} />
    </Router>
  );
}

Motivation 🔦

No response

@huseeiin huseeiin added the enhancement New feature or request label Jul 3, 2024
@huseeiin huseeiin changed the title [Feature?]: Add a sync option to FileRoutes or a async option that is false by default to disable lazy loading all routes [Feature?]: Add an option to disable lazy loading in <FileRoutes /> Jul 3, 2024
@ryansolid
Copy link
Member

I do have some concerns about giving control here when it comes to future routing approaches including lazy route manifest shipping. It might be valuable to see what this feature looks like in other frameworks. I'm curious how Next, Sveltekit, Remix, Nuxt, etc handle this.

@doeixd
Copy link
Contributor

doeixd commented Jul 3, 2024

Would this work?

async function createEagerFileRoutes() {
  const routes = <FileRoutes />;
  const eagerRoutes = []

  for (let route of (routes || [])) {
    if (route.info?.eager) {
      const component = await route['$component'].import();
      eagerRoutes.push(<Route path={route.path} component={component} load={route.load} />)
    } else {
      eagerRoutes.push(route)
    }
  }

  return (props) => eagerRoutes
}

const EagerFileRoutes = await createEagerFileRoutes();

@huseeiin
Copy link
Contributor Author

huseeiin commented Jul 3, 2024

Would this work?

async function createEagerFileRoutes() {
  const routes = <FileRoutes />;
  const eagerRoutes = []

  for (let route of (routes || [])) {
    if (route.info?.eager) {
      const component = await route['$component'].import();
      eagerRoutes.push(<Route path={route.path} component={component} load={route.load} />)
    } else {
      eagerRoutes.push(route)
    }
  }

  return (props) => eagerRoutes
}

const EagerFileRoutes = await createEagerFileRoutes();

i forgot the word "eager" here. important keyword.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants