question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Internal error: an internal `assert()` failed

See original GitHub issue
Error: [vite-plugin-ssr@0.2.0]
[Internal Failure] You stumbled upon a bug in `vite-plugin-ssr`'s source code (an internal `assert()` failed). This should definitely not be happening, and you should create a new GitHub issue at https://github.com/brillout/vite-plugin-ssr/issues/new that includes this error stack (the error stack is usually enough to debug internal errors). Or reach out on Discord. A fix will be written promptly.
    at Object.normalizePath (node_modules/vite-plugin-ssr/utils/normalizePath.ts:7:3)
    at node_modules/vite-plugin-ssr/html/injectAssets.node.ts:61:36
    at Array.map (<anonymous>)
    at Object.getPageAssets (node_modules/vite-plugin-ssr/html/injectAssets.node.ts:60:27)
    at populatePageContext (node_modules/vite-plugin-ssr/renderPage.node.ts:434:22)
    at renderPageId (node_modules/vite-plugin-ssr/renderPage.node.ts:159:3)
    at renderPage (node_modules/vite-plugin-ssr/renderPage.node.ts:131:20)
    at server/index.ts:53:20

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
brilloutcommented, Jul 19, 2021

Nice 👌. I added a new docs page https://vite-plugin-ssr.com/i18n.

As for conditional client side dependencies, it’s more a Vite thing so I’ll leave it to the Vite docs which is I believe in a good state in that regard.

0reactions
mate-hcommented, Jul 19, 2021

I would like to share my findings with anyone who might come across the common issues when adding SSR support to their own site. I will describe my experience while adding SSR support to an early stage production site.

Conditional client side dependencies

Here is how to conditionally import client side dependencies and components.

let clientSideDependency = { serverMock: true };
let ClientSideComponent = ({children}) => <div>{children}</div>;

// If browser context, not in a NodeJS SSR context
if (!import.meta.env.SSR) {
  import("client-side-dependency").then(module => clientSideDependency = module.default)
  import("client-side-component").then(module => ClientSideComponent = module.default)
}

Combining vite-plugin-ssr and ssr-window may be a good temporary drop-in solution if you don’t feel like refactoring everything at once for a large codebase. Some third party libraries may depend on the DOM this way too, like editorjs, and so they do not support SSR unless you include this snippet.

import { ssrWindow, ssrDocument } from "ssr-window";

// In a NodeJS Context
globals.window = ssrWindow;
globals.document = ssrDocument;

SSR language support

When a page is being rendered by the server, a client may specify an Accept-Language: es header, a ?lang=es query parameter, a domain TLD domain.es, or a path segment domain.com/es. These parameters will control which language the page renders in. This can also be done at build time with a CI script, where each pre-rendered build output goes into its own language “folder”. e.g. domain.com/en/contact, domain.com/es/contacto, or they will be deployed onto separate application domains, e.g. domain.com/contact, domain.es/contacto. Here is how I added support for this in code.

server.ts

import parser from "accept-language-parser";

// url part to explicit default language mapping
let urlLanguageConfig = { "https://domain.com/es": "es", "https://domain.com": "en", "https://domain.es": "es" }
const renderPage = createPageRender({ viteDevServer, isProduction, root });
app.get("*", async (req, res, next) => {
  const url = req.originalUrl;
  const foundUrl = Object.keys(urlLanguageConfig).find(k => url.includes(k))
  const defaultLanguage = "en";
  const acceptedLanguages = parser.parse(req.headers["accept-language"]);
  // application language
  let language = defaultLanguage;
  // in order of specificity
  if (acceptedLanguages.length > 0) {
    // perform language matching against supported languages
    language = acceptedLanguages[0].code;
  }
  if (foundUrl) language = urlLanguageConfig[foundUrl];

  const pageContext = {
    url,
    language
  };
  const result = await renderPage(pageContext);
  if (result.nothingRendered) return next();
  res.status(result.statusCode).send(result.renderResult);
});

types.ts

import type { PageContextBuiltIn } from "vite-plugin-ssr/types";
export type PageProps = {};
export type PageContext = PageContextBuiltIn & {
  Page: (pageProps: PageProps) => JSX.Element;
  pageProps: PageProps;
  url: string;
  language: string;
  documentProps?: {
    title?: string;
    description?: string;
  };
};

_default.page.server.tsx

const { documentProps, language: lang } = pageContext;
const title = (documentProps && documentProps.title) || getMsg("document.default-title", lang);
const desc = (documentProps && documentProps.description) || getMsg("document.default-description", lang);

return html`<!DOCTYPE html>
  <html lang="${lang}">
    <head>
      <meta charset="UTF-8" />
      <meta http-equiv="content-language" content="${lang}">
      <link rel="icon" href="${logoUrl}" />
      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      <meta name="description" content="${desc}" />
      <title>${title}</title>
    </head>
    <body>
      <div id="page-view">${html.dangerouslySkipEscape(pageHtml.html)}</div>
    </body>
  </html>`;
Read more comments on GitHub >

github_iconTop Results From Across the Web

INTERNAL ASSERT FAILED error · Issue #75746 - GitHub
While training my CNN for muscle segmentation, I'm running into an error message that affects the stability and predictability of CNN learning.
Read more >
3700 Internal error: An assertion failed. - Teradata Database
3700 Internal error: An assertion failed. Explanation: This error occurs only if an inconsistency was detected by the syntaxer.
Read more >
INTERNAL ASSERT FAILED: removeWrite called with ...
Hello, I'm getting the below error, causing my Node.js app to fail. I have two questions. 1. Why does this error occur? 2....
Read more >
Known Issue: DT140520 - IBM
Internal Error Assertion Failed when assigning in OplScript to a model element a value with an inconsistent type. If the model element is...
Read more >
infrun.c:6384: internal-error: void process_event_stop_test ...
A problem internal to GDB has been detected, further debugging may prove unreliable. ... line=6384, fmt=0xe34269 "%s: Assertion `%s' failed.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found