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

[✨] Allow data to be passed in StaticGenerateHandler #6172

Open
adaliszk opened this issue Apr 28, 2024 · 0 comments
Open

[✨] Allow data to be passed in StaticGenerateHandler #6172

adaliszk opened this issue Apr 28, 2024 · 0 comments
Labels
STATUS-1: needs triage New issue which needs to be triaged TYPE: enhancement New feature or request

Comments

@adaliszk
Copy link
Contributor

adaliszk commented Apr 28, 2024

Is your feature request related to a problem?

I'm trying to load non-serializable data, typically JSX, with the statically generated routes. However, when building imports dynamically, the frameworks force serialization, or I must skip that and cannot render with SSR.

Describe the solution you'd like

I would like it if there would be a way to pass a Content JSX function for each statically generated route on build time so that when it gets rendered, there would be a <Content /> component to be used and inlined without trying to serialize into JSON.

So ideally, something like:

export const onStaticGenerate: StaticGenerateHandler = async () => {
    const slugs = ["foo", "bar", "qux"];
    const contents = {}
    for await (const slug of slugs) {
        contents[slug] = await readMarkdown({ file: `../../content/${slug}.md` });
        // ^ yields a { frontmatter: Record<string, unknown>, Content: () => JSXNode }
    }
    return {
        params: slugs.map((slug) => ({ slug })),
        data: contents,
    };
};


export default component$(() => {
    const { params, data } = useLocation();
    const { Content } = data

    return (
        <>
            <h1>/{loc.params.slug}</h1>
            <Content />
        </>
    );
});

Describe alternatives you've considered

The dynamic import works with noSerialize, but when navigating around in development mode, the contents disappear. I considered forcing the compiler somehow, not automatically, to serialize a JSX function, but I found no suitable solution.
As an alternative, I also considered just generating index files with all the contents already imported statically, but before I commit to that solution, I wanted to raise a request here.

Additional context

I have a repository where I am trying to implement this; it can be opened in stackblitz at: https://stackblitz.com/github/adaliszk/web-sandbox/tree/develop/apps/qwik-website

@adaliszk adaliszk added STATUS-1: needs triage New issue which needs to be triaged TYPE: enhancement New feature or request labels Apr 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
STATUS-1: needs triage New issue which needs to be triaged TYPE: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant