Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasHT22 authored Mar 21, 2023
2 parents 867ca2c + f7870fb commit cf03d20
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/components/big-interactive-pages/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Help from '../popups-etc/help'
import { collapseRanges } from '../../lib/codemirror/util'
import { defaultExampleCode } from '../../lib/examples'
import MigrateToast from '../popups-etc/migrate-toast'
import { nanoid } from 'nanoid'

interface EditorProps {
persistenceState: Signal<PersistenceState>
Expand Down Expand Up @@ -164,6 +165,26 @@ export default function Editor({ persistenceState, cookies }: EditorProps) {
initialCode = persistenceState.value.code
else if (persistenceState.value.kind === 'IN_MEMORY')
initialCode = defaultExampleCode

// Firefox has weird tab restoring logic. When you, for example, Ctrl-Shift-T, it opens
// a kinda broken cached version of the page. And for some reason this reverts the CM
// state. Seems like manipulating Preact state is unpredictable, but sessionStorage is
// saved, so we use a random token to detect if the page is being restored and force a
// reload.
//
// See https://github.com/hackclub/sprig/issues/919 for a bug report this fixes.
useEffect(() => {
const pageId = nanoid()
window.addEventListener('unload', () => {
sessionStorage.setItem(pageId, pageId)
})
window.addEventListener('load', () => {
if (sessionStorage.getItem(pageId)) {
sessionStorage.removeItem('pageId')
window.location.reload()
}
})
}, [ initialCode ])

return (
<div class={styles.page}>
Expand Down
7 changes: 6 additions & 1 deletion src/lib/game-saving/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ export const loginCodeTemplate = (code: string): EmailSpec => ({
html: `
<p>Here's your Sprig login code:</p>
<h1>${code}</h1>
<p><small>(Not you? You can safely ignore this email.)</small></p>
`,
text: `Here's your Sprig login code: ${code}`
text: [
`Here's your Sprig login code: ${code}`,
'',
'(Not you? You can safely ignore this email.)'
].join('\n')
})

export const tempGameTemplate = (user: User, game: Game): EmailSpec => {
Expand Down

0 comments on commit cf03d20

Please sign in to comment.