Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 7 additions & 2 deletions src/components/footer/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ import style from './style.module.css';
* Display a random contributor of the list above.
*/
function useContributors() {
const contributors = useResource(() =>
fetch('/contributors.json').then(r => r.json()),
const contributors = useResource(
() =>
fetch('/contributors.json', {
credentials: 'include',
mode: 'no-cors',
Comment on lines +30 to +31
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's essential that these are set to these specific values for Safari support.

Not entirely sure why this is, as it deviates from Chrome & FF, but it's been the case for going on 5 years now so I don't think the Safari team particularly cares about aligning. Here's an StackOverflow post about it.

priority: 'low'
}).then(r => r.json()),
['/contributors.json']
);

Expand Down
12 changes: 12 additions & 0 deletions src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as hooks from 'preact/hooks';
import { hydrate, prerender as ssr } from 'preact-iso';

import App from './components/app';
import { getContentPath } from './lib/use-content.js';
import './analytics';
import './style/index.css';

Expand Down Expand Up @@ -59,7 +60,18 @@ export async function prerender() {
{ type: 'meta', props: { property: 'og:url', content: `https://preactjs.com${location.pathname}` } },
{ type: 'meta', props: { property: 'og:title', content: globalThis.title } },
{ type: 'meta', props: { property: 'og:description', content: globalThis.description } },

// Make sure old v8 docs aren't indexed by search engines, leads to confused users if they land there
location.pathname.includes('/v8/') && { type: 'meta', props: { name: 'robots', content: 'noindex' } },

// Preloading
// These are all low priority, non-blocking fetches that we just want to have started early. None are critical due to prerendering.
{ type: 'link', props: { rel: 'preload', href: '/.netlify/functions/release?repo=preact', as: 'fetch', fetchpriority: 'low' } },
location.pathname == '/' && { type: 'link', props: { rel: 'preload', href: '/.netlify/functions/repos?org=preactjs', as: 'fetch', fetchpriority: 'low' } },
{ type: 'link', props: { rel: 'preload', href: '/contributors.json', as: 'fetch', fetchpriority: 'low' } },
// Hardcoding English is intentional, first render always fetches it with user preference only being applied later
{ type: 'link', props: { rel: 'preload', href: `/content/en${getContentPath(location.pathname)}.json`, as: 'fetch', fetchpriority: 'low' } },

process.env.BRANCH && { type: 'script', children: `ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga('set','dimension1','${process.env.BRANCH}');onerror=function(e,f,l,c){ga('send','event','exception',e,f+':'+l+':'+c)}` }
].filter(Boolean));

Expand Down
2 changes: 1 addition & 1 deletion src/lib/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export async function getContent([lang, name]) {
url = url.endsWith('/') ? url.replace(/\/$/, '.json') : url + '.json';

let fallback = false;
return await fetch(url)
return await fetch(url, { credentials: 'include', mode: 'no-cors' })
.then(r => {
// fall back to english
if (!r.ok && lang != 'en') {
Expand Down
12 changes: 10 additions & 2 deletions src/lib/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,21 @@ function checkStatus(r) {
const baseUrl = '/.netlify/functions/';

export const fetchOrganizationRepos = org =>
fetch(`${baseUrl}repos?org=${org}`, { credentials: 'omit' })
fetch(`${baseUrl}repos?org=${org}`, {
credentials: 'include',
mode: 'no-cors',
priority: 'low'
})
.then(checkStatus)
.then(r => r.json())
.catch(() => getFallbackData().preactOrgRepos);

export const fetchRelease = repo =>
fetch(`${baseUrl}release?repo=${repo}`, { credentials: 'omit' })
fetch(`${baseUrl}release?repo=${repo}`, {
credentials: 'include',
Comment on lines -23 to +28
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm lacking the context for why credentials: 'omit' was set (as the blame has none), but it shouldn't be an issue for us as we're not directly fetching from the GitHub API, it always passes through our lambda/approximation of a lambda (when running locally). Request & Response headers/cookies won't make it through that layer.

mode: 'no-cors',
priority: 'low'
})
.then(checkStatus)
.then(r => r.json())
.catch(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/use-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
* @param {string} path
* @returns {string}
*/
function getContentPath(path) {
export function getContentPath(path) {
if (path == '/') return '/index';
if (path == '/tutorial') return '/tutorial/index';
return path;
Expand Down