Xiphe / remix-island

utils to render remix into a dom-node instead of the whole document
MIT License
139 stars 8 forks source link

All JS modulepreload tags are within ROOT DIV element #21

Open jvenki opened 5 days ago

jvenki commented 5 days ago

Thanks for creating this wonderful library to enable Selective Hydration.

After this change, I find all the "modulepreload" link tags placed within our new <div id="root"> element. I am not sure why though Remix's Meta and Links are within the createHead method only.

export const Head = createHead(() => {
    const data = useRouteLoaderData<typeof loader>("root");
    return (
        <>
            <meta charSet="utf-8" />
            <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=3.0, interactive-widget=resizes-content" />
            <meta name="robots" content="index, follow" />
            <Meta />
            <Links />
        </>
    );
});

I am also using Layout Export feature of Remix and my Layout is as follows

export function Layout({ children }: { children: React.ReactNode }) {
    return (
        <>
            <Head />
            {children}
            <ScrollRestoration />
            <Scripts />
        </>
    );
}

Is there anything I am doing wrong here? This is just placing the various modulepreload tags later when it should ideally have been in the head

jvenki commented 5 days ago

Is it because we are doing renderToString on HEAD and Meta and Links do not have any context on the current route and therefore not reading the vite manifest properly to inject the relevant modulepreload links. Later, <Scripts /> is bringing it and somehow moving it to the top of the ROOT element.