Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/fredPublic

MDN's frontend since late 2025, built with Web Components, Lit, and SSR for a fast, clean documentation experience. Fred = /fr(ont)e(n)d/.

License

NotificationsYou must be signed in to change notification settings

mdn/fred

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

MDN's next fr(ont)e(n)d.

Getting started

  1. Copy.env-dist to.env and update values as needed. The file contains comments for guidance:
   cp .env-dist .env
  1. Install dependenciesnpm install
  2. Bring up the dev environment withnpm run start

Commands

  • npm run start
    • runs the rari server and the live-reloading development server together
    • run withNODE_ENV=production to run rari with the preview server, you'll need to have runnpm run build first
  • node --env-file=.env --run rari -- serve
    • runs the rari server
    • necessary fornpm run dev andnpm run preview
  • npm run dev
    • brings up the live-reloading development server, likely what you want for doing local development
  • npm run build
    • builds the production js/css/asset bundles
    • must be run at least once fornpm run preview to work
  • npm run preview
    • runs the preview server: using the production bundles with the rari server: useful for testing our prod rspack config

Accessing from non-localhost

If you want to access fred from a different machine, you'll need to run with certain options:

  • HTTPS=true to enable HTTPS with a self-signed certificate, allowing Web APIs requiring a secure context to work
  • ORIGIN_MAIN=your.local.ip.address to allowlist your address in the playground

So a full command might look like:

HTTPS=true ORIGIN_MAIN=192.168.0.99 npm run start

This is useful to test changes on mobile, tablets and other platforms.

Development principles

Supported Browsers

tl;dr For visitors to MDN, we support theBaseline widely available browser set, with some minor modifications.

Browsers

TheBaseline widely available browser set is defined as browsers from theCore browser set whose initial release date is on or before 30 months prior to today's date, plus long-term support releases.

MDN supports these browsers, along with Firefox for iOS and all currently active Firefox ESR versions:

  • Apple Safari (iOS, macOS) — released within the last 2½ years
  • Google Chrome (Android, Desktop) — released within the last 2½ years
  • Microsoft Edge (Desktop) — released within the last 2½ years
  • Mozilla Firefox (Android, Desktop, iOS) — released within the last 2½ years
  • Mozilla Firefox ESR — currently supported by Mozilla

"Supported"

In this context,supported means that any issues with rendering or functionality are considered bugs and will be addressed as soon as reasonably possible.

For issues encountered while using unsupported browsers, we decide on a case-by-case assessment of whether the issue will be addressed; however, these issues may have lower priority. Issues with screen readers and other accessibility aids are likely to carry higher levels of importance.

We make our best efforts to design MDN to degrade gracefully; however, there are no guarantees of any level of functionality outside the supported browser set.

Environment variables

Seethe environment variables README.

Inline JS

We need to run some JS as soon as possible at page load, to avoid layout shifts and flashes.We place this JS inentry.inline.js, and it's inlined on page load.Rspack also generates the necessary CSP hash when doing a prod build withnpm run build.

If this code is component-specific, it can beimported with?source&csp=true and used to set the value ofstatic inlineScript in a Server Component.Remember to add an additional entry to the CSP hashes in yari when doing so.

Custom Imports

We support a range of non-standard imports in our JavaScript. This includes:

?source

Imports the raw source of the file as a string.

importtextfrom"./some-file.txt?source";

&csp=true

Logs a CSP hash for the source of the file during the production build.Most commonly used alongside?source to import the source of a file for inlining in a component, which needs to be allowlisted in our CSP:

importinlineScriptfrom"./inline.js?source&csp=true";

Layout

Seethe layout README.

Media queries

Seethe media queries README.

Sandbox

We have a basic sandbox for testing and styling components in isolation athttp://localhost:3000/sandbox

To add a component to the sandbox, add asandbox.js file to the component, which exports a class named likeMyComponentSandbox which extends theSandboxComponent exported fromcomponents/sandbox/class.js.

Components and Elements

  • Components should live in thecomponents/ folder, with reserved names which cause certain behavior, explained further below:
    • component-name/
      • global.css - (reserved): automatically added to global styles
      • element.js - (reserved): custom element, automatically imported client side, always imported server side
      • element.css - (recommended): styles for custom element's shadow dom
      • server.js - (reserved): server component, will automatically load the adjacentserver.css file when used
      • server.css - (reserved): automatically added to page styles when its server component is used in that page
  • global.css: components which have CSS which should be loaded onall pages should expose that through aglobal.css file:
    • This should be used sparingly, use it for things needed in almost all components, like colors, fonts, etc.
    • Or, when creating a custom element, use it to set the "browser default" styles on that custom element: usually as simple as justmdn-component-name { display: block; } or similar
  • element.js: custom elements should be defined incomponents/component-name/element.js
    • The class should be exported, and namedMDNComponentName
      • Acronyms should be kept all caps, to match the naming ofHTMLElement class names, and added toACRONYMS inbuild/plugins/generate-element-map.js to allow the correct types to be generated
    • The element should be registered with a name ofmdn-component-name
    • If all this is done:
      • The element will be automatically loaded client side if it's present in the DOM at page load
        • Elements inserted client side (i.e. in a hook, or another custom element) won't be automatically loaded, and the hook should handle loading them: probably with an asyncimport()
      • The element will be automatically loaded server side for SSR
      • The element will automatically be added totypes/element-map.d.ts to provide proper types in e.g.querySelector("mdn-component-name")
  • server.js: server components should be defined incomponents/component-name/server.js
    • The class should extendServerComponent fromcomponents/server/index.js, and be namedComponentName
  • server.css: server component styles should be placed incomponents/component-name/server.css
    • These will be automatically loaded server side when the adjacentServerComponent is used
      • Therefore, these styles should be scoped to the component, usually with a wrapping class

Typing

  • We useTypeScript in JSDoc annotations for typing, so we can write and directly execute JavaScript (with no transpilation step)
  • We occasionally use TypeScript files directly for writing types/interface which are too complex to easily write in JSDoc
  • Eventually we'll have a fully typed codebase, with no errors: while we're in active development we can ignore errors in the interest of development speed/pragmatism:
    • If we do so, we should use// @ts-expect-error so we get an error when we fix the error and don't leave unnecessary// @ts-ignore comments lying around. While we're in active development these can lack a comment, but eventually we'll require an explanatory comment on each.

Hydration errors

If our server side rendered custom elements are different to the initial state of our custom elements when rendered client side, Lit will error out during hydration, stopping the execution of our client side JS.

To avoid this, don't compute things that are server/client dependent inconnectedCallback (or run functions which do this). Instead you must run these infirstUpdated (despite the warning lit will raise in development about the element scheduling an update after an update completed).

This issue is tracked upstream:lit/lit#1434

About

MDN's frontend since late 2025, built with Web Components, Lit, and SSR for a fast, clean documentation experience. Fred = /fr(ont)e(n)d/.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Contributors21


[8]ページ先頭

©2009-2025 Movatter.jp