-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
(chore) - create Preact example #1636
Closed
Closed
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
899e95c
add preact example
JoviDeCroock 68e2f9f
fix bug where a dependent missing module would trigger a misleaading …
JoviDeCroock c7f8275
add name to contributors
JoviDeCroock 6cc41b8
Update examples/basic-preact/app/root.tsx
JoviDeCroock 764800e
Merge branch 'main' into preact-example
JoviDeCroock File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,7 @@ | |
- joaosamouco | ||
- johannesbraeunig | ||
- johnson444 | ||
- JoviDeCroock | ||
- juhanakristian | ||
- juwiragiye | ||
- kalch | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
node_modules | ||
|
||
/.cache | ||
/build | ||
/public/build | ||
/package-lock.json | ||
/yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Welcome to Remix! | ||
|
||
This is a very basic example of a simple Remix app using the Remix App Server. | ||
|
||
- [Remix Docs](https://remix.run/docs) | ||
|
||
## Development | ||
|
||
From your terminal: | ||
|
||
```sh | ||
npm install | ||
npm run dev | ||
``` | ||
|
||
This starts your app in development mode, rebuilding assets on file changes. | ||
|
||
## Deployment | ||
|
||
First, build your app for production: | ||
|
||
```sh | ||
npm run build | ||
``` | ||
|
||
Then run the app in production mode: | ||
|
||
```sh | ||
npm start | ||
``` | ||
|
||
## Preview | ||
|
||
Open this example on [CodeSandbox](https://codesandbox.com): | ||
|
||
[![Open in CodeSandbox](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/remix-run/remix/tree/main/examples/basic) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { hydrate } from "react-dom"; | ||
import { RemixBrowser } from "remix"; | ||
|
||
const documentElement = document.documentElement; | ||
const apply = (n: HTMLElement) => document.replaceChild(n, documentElement); | ||
// Temp fix | ||
hydrate(<RemixBrowser />, { | ||
childNodes: [documentElement], | ||
firstChild: documentElement, | ||
insertBefore: apply, | ||
appendChild: apply | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { renderToString } from "react-dom/server"; | ||
import { RemixServer } from "remix"; | ||
import type { EntryContext } from "remix"; | ||
|
||
export default function handleRequest( | ||
request: Request, | ||
responseStatusCode: number, | ||
responseHeaders: Headers, | ||
remixContext: EntryContext | ||
) { | ||
const markup = renderToString( | ||
<RemixServer context={remixContext} url={request.url} /> | ||
); | ||
|
||
responseHeaders.set("Content-Type", "text/html"); | ||
|
||
return new Response("<!DOCTYPE html>" + markup, { | ||
status: responseStatusCode, | ||
headers: responseHeaders | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,248 @@ | ||
import * as React from "react"; | ||
import { | ||
Link, | ||
Links, | ||
LiveReload, | ||
Meta, | ||
Outlet, | ||
Scripts, | ||
ScrollRestoration, | ||
useCatch, | ||
useLocation | ||
} from "remix"; | ||
import type { LinksFunction } from "remix"; | ||
|
||
import deleteMeRemixStyles from "~/styles/demos/remix.css"; | ||
import globalStylesUrl from "~/styles/global.css"; | ||
import darkStylesUrl from "~/styles/dark.css"; | ||
|
||
/** | ||
* The `links` export is a function that returns an array of objects that map to | ||
* the attributes for an HTML `<link>` element. These will load `<link>` tags on | ||
* every route in the app, but individual routes can include their own links | ||
* that are automatically unloaded when a user navigates away from the route. | ||
* | ||
* https://remix.run/api/app#links | ||
*/ | ||
export const links: LinksFunction = () => { | ||
return [ | ||
{ rel: "stylesheet", href: globalStylesUrl }, | ||
{ | ||
rel: "stylesheet", | ||
href: darkStylesUrl, | ||
media: "(prefers-color-scheme: dark)" | ||
}, | ||
{ rel: "stylesheet", href: deleteMeRemixStyles } | ||
]; | ||
}; | ||
|
||
/** | ||
* The root module's default export is a component that renders the current | ||
* route via the `<Outlet />` component. Think of this as the global layout | ||
* component for your app. | ||
*/ | ||
export default function App() { | ||
return ( | ||
<Document> | ||
<Layout> | ||
<Outlet /> | ||
</Layout> | ||
</Document> | ||
); | ||
} | ||
|
||
function Document({ | ||
children, | ||
title | ||
}: { | ||
children: React.ReactNode; | ||
title?: string; | ||
}) { | ||
return ( | ||
<html lang="en"> | ||
<head> | ||
<meta charSet="utf-8" /> | ||
<meta name="viewport" content="width=device-width,initial-scale=1" /> | ||
{title ? <title>{title}</title> : null} | ||
<Meta /> | ||
<Links /> | ||
</head> | ||
<body> | ||
{children} | ||
<RouteChangeAnnouncement /> | ||
<ScrollRestoration /> | ||
<Scripts /> | ||
{process.env.NODE_ENV === "development" ? <LiveReload /> : null} | ||
JoviDeCroock marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</body> | ||
</html> | ||
); | ||
} | ||
|
||
function Layout({ children }: React.PropsWithChildren<{}>) { | ||
return ( | ||
<div className="remix-app"> | ||
<header className="remix-app__header"> | ||
<div className="container remix-app__header-content"> | ||
<Link to="/" title="Remix" className="remix-app__header-home-link"> | ||
<RemixLogo /> | ||
</Link> | ||
<nav aria-label="Main navigation" className="remix-app__header-nav"> | ||
<ul> | ||
<li> | ||
<Link to="/">Home</Link> | ||
</li> | ||
<li> | ||
<a href="https://remix.run/docs">Remix Docs</a> | ||
</li> | ||
<li> | ||
<a href="https://github.com/remix-run/remix">GitHub</a> | ||
</li> | ||
</ul> | ||
</nav> | ||
</div> | ||
</header> | ||
<div className="remix-app__main"> | ||
<div className="container remix-app__main-content">{children}</div> | ||
</div> | ||
<footer className="remix-app__footer"> | ||
<div className="container remix-app__footer-content"> | ||
<p>© You!</p> | ||
</div> | ||
</footer> | ||
</div> | ||
); | ||
} | ||
|
||
export function CatchBoundary() { | ||
const caught = useCatch(); | ||
|
||
let message; | ||
switch (caught.status) { | ||
case 401: | ||
message = ( | ||
<p> | ||
Oops! Looks like you tried to visit a page that you do not have access | ||
to. | ||
</p> | ||
); | ||
break; | ||
case 404: | ||
message = ( | ||
<p>Oops! Looks like you tried to visit a page that does not exist.</p> | ||
); | ||
break; | ||
|
||
default: | ||
throw new Error(caught.data || caught.statusText); | ||
} | ||
|
||
return ( | ||
<Document title={`${caught.status} ${caught.statusText}`}> | ||
<Layout> | ||
<h1> | ||
{caught.status}: {caught.statusText} | ||
</h1> | ||
{message} | ||
</Layout> | ||
</Document> | ||
); | ||
} | ||
|
||
export function ErrorBoundary({ error }: { error: Error }) { | ||
console.error(error); | ||
return ( | ||
<Document title="Error!"> | ||
<Layout> | ||
<div> | ||
<h1>There was an error</h1> | ||
<p>{error.message}</p> | ||
<hr /> | ||
<p> | ||
Hey, developer, you should replace this with what you want your | ||
users to see. | ||
</p> | ||
</div> | ||
</Layout> | ||
</Document> | ||
); | ||
} | ||
|
||
function RemixLogo(props: React.ComponentPropsWithoutRef<"svg">) { | ||
return ( | ||
<svg | ||
viewBox="0 0 659 165" | ||
version="1.1" | ||
xmlns="http://www.w3.org/2000/svg" | ||
xmlnsXlink="http://www.w3.org/1999/xlink" | ||
aria-labelledby="remix-run-logo-title" | ||
role="img" | ||
width="106" | ||
height="30" | ||
fill="currentColor" | ||
{...props} | ||
> | ||
<title id="remix-run-logo-title">Remix Logo</title> | ||
<path d="M0 161V136H45.5416C53.1486 136 54.8003 141.638 54.8003 145V161H0Z M133.85 124.16C135.3 142.762 135.3 151.482 135.3 161H92.2283C92.2283 158.927 92.2653 157.03 92.3028 155.107C92.4195 149.128 92.5411 142.894 91.5717 130.304C90.2905 111.872 82.3473 107.776 67.7419 107.776H54.8021H0V74.24H69.7918C88.2407 74.24 97.4651 68.632 97.4651 53.784C97.4651 40.728 88.2407 32.816 69.7918 32.816H0V0H77.4788C119.245 0 140 19.712 140 51.2C140 74.752 125.395 90.112 105.665 92.672C122.32 96 132.057 105.472 133.85 124.16Z" /> | ||
<path d="M229.43 120.576C225.59 129.536 218.422 133.376 207.158 133.376C194.614 133.376 184.374 126.72 183.35 112.64H263.478V101.12C263.478 70.1437 243.254 44.0317 205.11 44.0317C169.526 44.0317 142.902 69.8877 142.902 105.984C142.902 142.336 169.014 164.352 205.622 164.352C235.83 164.352 256.822 149.76 262.71 123.648L229.43 120.576ZM183.862 92.6717C185.398 81.9197 191.286 73.7277 204.598 73.7277C216.886 73.7277 223.542 82.4317 224.054 92.6717H183.862Z" /> | ||
<path d="M385.256 66.5597C380.392 53.2477 369.896 44.0317 349.672 44.0317C332.52 44.0317 320.232 51.7117 314.088 64.2557V47.1037H272.616V161.28H314.088V105.216C314.088 88.0638 318.952 76.7997 332.52 76.7997C345.064 76.7997 348.136 84.9917 348.136 100.608V161.28H389.608V105.216C389.608 88.0638 394.216 76.7997 408.04 76.7997C420.584 76.7997 423.4 84.9917 423.4 100.608V161.28H464.872V89.5997C464.872 65.7917 455.656 44.0317 424.168 44.0317C404.968 44.0317 391.4 53.7597 385.256 66.5597Z" /> | ||
<path d="M478.436 47.104V161.28H519.908V47.104H478.436ZM478.18 36.352H520.164V0H478.18V36.352Z" /> | ||
<path d="M654.54 47.1035H611.788L592.332 74.2395L573.388 47.1035H527.564L568.78 103.168L523.98 161.28H566.732L589.516 130.304L612.3 161.28H658.124L613.068 101.376L654.54 47.1035Z" /> | ||
</svg> | ||
); | ||
} | ||
|
||
/** | ||
* Provides an alert for screen reader users when the route changes. | ||
*/ | ||
const RouteChangeAnnouncement = React.memo(() => { | ||
const [hydrated, setHydrated] = React.useState(false); | ||
const [innerHtml, setInnerHtml] = React.useState(""); | ||
const location = useLocation(); | ||
|
||
React.useEffect(() => { | ||
setHydrated(true); | ||
}, []); | ||
|
||
const firstRenderRef = React.useRef(true); | ||
React.useEffect(() => { | ||
// Skip the first render because we don't want an announcement on the | ||
// initial page load. | ||
if (firstRenderRef.current) { | ||
firstRenderRef.current = false; | ||
return; | ||
} | ||
|
||
const pageTitle = | ||
location.pathname === "/" ? "Remix demo home page" : document.title; | ||
setInnerHtml(`Navigated to ${pageTitle}`); | ||
}, [location.pathname]); | ||
|
||
// Render nothing on the server. The live region provides no value unless | ||
// scripts are loaded and the browser takes over normal routing. | ||
if (!hydrated) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div | ||
aria-live="assertive" | ||
aria-atomic | ||
id="route-change-region" | ||
style={{ | ||
border: "0", | ||
clipPath: "inset(100%)", | ||
clip: "rect(0 0 0 0)", | ||
height: "1px", | ||
margin: "-1px", | ||
overflow: "hidden", | ||
padding: "0", | ||
position: "absolute", | ||
width: "1px", | ||
whiteSpace: "nowrap", | ||
wordWrap: "normal" | ||
}} | ||
> | ||
{innerHtml} | ||
</div> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Outlet } from "remix"; | ||
import type { MetaFunction, LinksFunction } from "remix"; | ||
|
||
import stylesUrl from "~/styles/demos/about.css"; | ||
|
||
export const meta: MetaFunction = () => { | ||
return { | ||
title: "About Remix" | ||
}; | ||
}; | ||
|
||
export const links: LinksFunction = () => { | ||
return [{ rel: "stylesheet", href: stylesUrl }]; | ||
}; | ||
|
||
export default function Index() { | ||
return ( | ||
<div className="about"> | ||
<div className="about__intro"> | ||
<h2>About Us</h2> | ||
<p> | ||
Ok, so this page isn't really <em>about us</em>, but we did want to | ||
show you a few more things Remix can do. | ||
</p> | ||
<p> | ||
Did you notice that things look a little different on this page? The | ||
CSS that we import in the route file and include in its{" "} | ||
<code>links</code> export is only included on this route and its | ||
children. | ||
</p> | ||
<p> | ||
Wait a sec...<em>its children</em>? To understand what we mean by | ||
this,{" "} | ||
<a href="https://remix.run/tutorial/4-nested-routes-params"> | ||
read all about nested routes in the docs | ||
</a> | ||
. | ||
</p> | ||
<hr /> | ||
<Outlet /> | ||
</div> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Preact currently fails when passing in
document
as that has a few nodes that aren't reconcilable 😅