-
Notifications
You must be signed in to change notification settings - Fork 404
Rework @solidjs/start/env
#2034
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
Changes from all commits
d59455e
194ae73
744f604
58affbc
d3c7a77
ce33624
459a1ca
4232aa1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@solidjs/start": patch | ||
| --- | ||
|
|
||
| Rework `@solidjs/start/env` |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // This file contains global type definitions that are exported as @solidjs/start/env | ||
|
|
||
| /// <reference types="vite/client" /> | ||
|
|
||
| declare namespace App { | ||
| export interface RequestEventLocals { | ||
| [key: string | symbol]: any; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,114 +1 @@ | ||
| import type { JSX } from "solid-js"; | ||
| import { createStore } from "solid-js/store"; | ||
| import { | ||
| createComponent, | ||
| getHydrationKey, | ||
| getOwner, | ||
| hydrate, | ||
| type MountableElement, | ||
| } from "solid-js/web"; | ||
|
|
||
| /** | ||
| * | ||
| * Read more: https://docs.solidjs.com/solid-start/reference/client/mount | ||
| */ | ||
| export function mount(fn: () => JSX.Element, el: MountableElement) { | ||
| if (import.meta.env.START_ISLANDS) { | ||
| const map = new WeakMap(); | ||
| async function mountIsland(el: HTMLElement) { | ||
| if (el.dataset.css) { | ||
| let css = JSON.parse(el.dataset.css); | ||
| for (let href of css) { | ||
| if (!document.querySelector(`link[href="${href}"]`)) { | ||
| let link = document.createElement("link"); | ||
| link.rel = "stylesheet"; | ||
| link.href = href; | ||
| document.head.appendChild(link); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| let mod = await import( | ||
| /* @vite-ignore */ | ||
| import.meta.env.MANIFEST["client"]!.chunks[el.dataset.id!.split("#")[0] as string]!.output | ||
| .path | ||
| ); | ||
| if (!mod || !el.dataset.hk) return; | ||
|
|
||
| let Component = mod[el.dataset.id!.split("#")[1] as string]; | ||
| let hk = el.dataset.hk; | ||
| // _$DEBUG("hydrating island", el.dataset.island, hk.slice(0, hk.length - 1) + `1-`, el); | ||
|
|
||
| let props = createStore({ | ||
| ...JSON.parse(el.dataset.props!), | ||
| get children() { | ||
| const p = el.getElementsByTagName("solid-children"); | ||
| getHydrationKey(); | ||
| [...p].forEach(a => { | ||
| (a as any).__$owner = getOwner(); | ||
| }); | ||
| return; | ||
| }, | ||
| }); | ||
|
|
||
| map.set(el, props); | ||
|
|
||
| hydrate(() => createComponent(Component, props[0]), el, { | ||
| renderId: hk.slice(0, hk.length - 1) + `${1 + Number(el.dataset.offset)}-`, | ||
| owner: lookupOwner(el), | ||
| }); | ||
|
|
||
| delete el.dataset.hk; | ||
| el.dataset.hkk = hk; | ||
| } | ||
|
|
||
| let queue: HTMLElement[] = []; | ||
| let queued = false; | ||
| function runTaskQueue(info: any) { | ||
| while (info.timeRemaining() > 0 && queue.length) { | ||
| mountIsland(queue.shift()!); | ||
| } | ||
| if (queue.length) { | ||
| requestIdleCallback(runTaskQueue); | ||
| } else queued = false; | ||
| } | ||
|
|
||
| const hydrateIslands = () => { | ||
| const islands: NodeListOf<HTMLElement> = document.querySelectorAll("solid-island[data-hk]"); | ||
| const assets = new Set<string>(); | ||
| islands.forEach((el: HTMLElement) => el.dataset.id && assets.add(el.dataset.id)); | ||
| Promise.all( | ||
| [...assets].map( | ||
| asset => | ||
| import( | ||
| /* @vite-ignore */ import.meta.env.MANIFEST["client"]!.chunks[ | ||
| asset.split("#")[0] as string | ||
| ]!.output.path | ||
| ), | ||
| ), | ||
| ) | ||
| .then(() => { | ||
| islands.forEach((el: HTMLElement) => { | ||
| if (el.dataset.when === "idle" && "requestIdleCallback" in window) { | ||
| if (!queued) { | ||
| queued = true; | ||
| requestIdleCallback(runTaskQueue); | ||
| } | ||
| queue.push(el); | ||
| } else mountIsland(el as HTMLElement); | ||
| }); | ||
| }) | ||
| .catch(e => console.error(e)); | ||
| }; | ||
|
|
||
| function lookupOwner(el: HTMLElement) { | ||
| const parent = el.closest("solid-children"); | ||
| return parent && (parent as any).__$owner; | ||
| } | ||
|
|
||
| hydrateIslands(); | ||
|
|
||
| return; | ||
| } | ||
| return hydrate(fn, el); | ||
| } | ||
| export { hydrate as mount } from "solid-js/web" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,17 @@ | ||
| // This file is an augmentation to the built-in ImportMeta interface | ||
| // Thus cannot contain any top-level imports | ||
| // <https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation> | ||
|
|
||
| /* eslint-disable @typescript-eslint/consistent-type-imports */ | ||
|
|
||
| declare namespace App { | ||
| export interface RequestEventLocals { | ||
| [key: string | symbol]: any; | ||
| } | ||
| } | ||
| // This file contains global type definitions that are internal to SolidStart and are not exported | ||
|
|
||
| declare module "solidstart:server-fn-manifest" { | ||
| type ServerFn = (...args: Array<any>) => Promise<any>; | ||
| export function getServerFnById(id: string): Promise<ServerFn>; | ||
| } | ||
|
|
||
| interface ImportMetaEnv extends Record<`VITE_${string}`, any>, SolidStartMetaEnv { | ||
| BASE_URL: string; | ||
| MODE: string; | ||
| DEV: boolean; | ||
| PROD: boolean; | ||
| SSR: boolean; | ||
| } | ||
| interface ImportMetaEnv extends SolidStartMetaEnv {} | ||
|
|
||
| interface SolidStartMetaEnv { | ||
| START_SSR: boolean; | ||
| START_APP_ENTRY: string; | ||
| START_CLIENT_ENTRY: string; | ||
| // START_ISLANDS: boolean; | ||
| START_ISLANDS: boolean; | ||
| // START_DEV_OVERLAY: boolean; | ||
| // SERVER_BASE_URL: string; | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.