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

fix: add error boundary to catch invalid code within the document code #1497

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dull-roses-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@solidjs/start": patch
---

fix: add error boundary to catch invalid code within the document code
96 changes: 49 additions & 47 deletions packages/start/src/server/StartServer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,59 +74,61 @@ export function StartServer(props: { document: Component<DocumentComponentProps>
return (
<NoHydration>
{docType as unknown as any}
<props.document
assets={
<>
<HydrationScript />
{context.assets.map((m: any) => renderAsset(m, nonce))}
</>
}
scripts={
nonce ? (
<ErrorBoundary>
<props.document
assets={
<>
<script
nonce={nonce}
innerHTML={`window.manifest = ${JSON.stringify(context.manifest)}`}
/>
<script
type="module"
nonce={nonce}
async
src={
import.meta.env.MANIFEST["client"]!.inputs[
import.meta.env.MANIFEST["client"]!.handler
]!.output.path
}
/>
<HydrationScript />
{context.assets.map((m: any) => renderAsset(m, nonce))}
</>
}
scripts={
nonce ? (
<>
<script
nonce={nonce}
innerHTML={`window.manifest = ${JSON.stringify(context.manifest)}`}
/>
<script
type="module"
nonce={nonce}
async
src={
import.meta.env.MANIFEST["client"]!.inputs[
import.meta.env.MANIFEST["client"]!.handler
]!.output.path
}
/>
</>
) : (
<>
<script innerHTML={`window.manifest = ${JSON.stringify(context.manifest)}`} />
<script
type="module"
async
src={
import.meta.env.MANIFEST["client"]!.inputs[
import.meta.env.MANIFEST["client"]!.handler
]!.output.path
}
/>
</>
)
}
>
{!import.meta.env.START_ISLANDS ? (
<Hydration>
<ErrorBoundary>
<App />
</ErrorBoundary>
</Hydration>
) : (
<>
<script innerHTML={`window.manifest = ${JSON.stringify(context.manifest)}`} />
<script
type="module"
async
src={
import.meta.env.MANIFEST["client"]!.inputs[
import.meta.env.MANIFEST["client"]!.handler
]!.output.path
}
/>
</>
)
}
>
{!import.meta.env.START_ISLANDS ? (
<Hydration>
<ErrorBoundary>
<App />
</ErrorBoundary>
</Hydration>
) : (
<ErrorBoundary>
<App />
</ErrorBoundary>
)}
</props.document>
)}
</props.document>
</ErrorBoundary>
</NoHydration>
);
}
69 changes: 36 additions & 33 deletions packages/start/src/server/spa/StartServer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { Component } from "solid-js";
import { NoHydration, getRequestEvent, ssr } from "solid-js/web";
import { renderAsset } from "../renderAsset";
import type { DocumentComponentProps, PageEvent } from "../types";
import { ErrorBoundary } from "../../shared/ErrorBoundary";

const docType = ssr("<!DOCTYPE html>");

Expand All @@ -18,39 +19,41 @@ export function StartServer(props: { document: Component<DocumentComponentProps>
return (
<NoHydration>
{docType as unknown as any}
<props.document
assets={<>{context.assets.map((m: any) => renderAsset(m))}</>}
scripts={
nonce ? (
<>
<script
nonce={nonce}
innerHTML={`window.manifest = ${JSON.stringify(context.manifest)}`}
/>
<script
type="module"
src={
import.meta.env.MANIFEST["client"]!.inputs[
import.meta.env.MANIFEST["client"]!.handler
]!.output.path
}
/>
</>
) : (
<>
<script innerHTML={`window.manifest = ${JSON.stringify(context.manifest)}`} />
<script
type="module"
src={
import.meta.env.MANIFEST["client"]!.inputs[
import.meta.env.MANIFEST["client"]!.handler
]!.output.path
}
/>
</>
)
}
/>
<ErrorBoundary>
<props.document
assets={<>{context.assets.map((m: any) => renderAsset(m))}</>}
scripts={
nonce ? (
<>
<script
nonce={nonce}
innerHTML={`window.manifest = ${JSON.stringify(context.manifest)}`}
/>
<script
type="module"
src={
import.meta.env.MANIFEST["client"]!.inputs[
import.meta.env.MANIFEST["client"]!.handler
]!.output.path
}
/>
</>
) : (
<>
<script innerHTML={`window.manifest = ${JSON.stringify(context.manifest)}`} />
<script
type="module"
src={
import.meta.env.MANIFEST["client"]!.inputs[
import.meta.env.MANIFEST["client"]!.handler
]!.output.path
}
/>
</>
)
}
/>
</ErrorBoundary>
</NoHydration>
);
}