Skip to content

fix(types): apply AppType generic to top-level props instead of pageP…#94117

Open
deeepanshu12 wants to merge 2 commits into
vercel:canaryfrom
deeepanshu12:fix-apptype-generic
Open

fix(types): apply AppType generic to top-level props instead of pageP…#94117
deeepanshu12 wants to merge 2 commits into
vercel:canaryfrom
deeepanshu12:fix-apptype-generic

Conversation

@deeepanshu12
Copy link
Copy Markdown

What this PR does / why we need it

This PR implements a workaround for a well-known visual glitch on iOS mobile browsers (Safari/WebKit) where swiping back on a dynamic page causes the previous screen to "flash" or "flicker" before the content fully loads.

The issue occurs because Safari takes a static snapshot of the current page for its swipe-back animation. By the time Next.js re-renders the previous page's DOM, the snapshot and the live DOM mismatch, causing the flicker.

The Fix (Approach 1): This PR adds global event listeners for pagehide and pageshow.

  • On pagehide (right before the user navigates away), we set document.body.style.opacity = '0'. Safari captures a transparent snapshot instead of the old page content.
  • On pageshow (when returning), we restore document.body.style.opacity = '1'.
    This completely eliminates the jarring flash of the wrong content.

Which issue(s) this fixes

Fixes #10465

Special notes for your reviewer

  • This is a non-intrusive CSS workaround that specifically targets the Safari snapshot behavior without hijacking native touch events.
  • Tested locally on iOS Safari to confirm the flicker is resolved and standard navigation is unaffected.

Copy link
Copy Markdown
Contributor

@vercel vercel Bot left a comment

Choose a reason for hiding this comment

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

Additional Suggestion:

MobileSwipeFix.tsx is a 0-byte empty file but is imported and rendered as a React component in layout.tsx, causing a build failure ("is not a module").

Fix on Vercel

Comment on lines +18 to +19
<html lang="en">
<body>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
<html lang="en">
<body>
<html
lang="en"
// Suppress hydration warnings here specifically because we'll modify the
// classname for the theme before React hydrates. This is to prevent a flash
// of incorrect theme.
suppressHydrationWarning
>
<head>
<script
// biome-ignore lint/security/noDangerouslySetInnerHtml: Needed to prevent flash of incorrect theme
dangerouslySetInnerHTML={{
__html: `
(function() {
const theme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
document.documentElement.classList.toggle('dark', theme === 'dark');
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
document.documentElement.classList.toggle('dark', e.matches);
});
})();
`,
}}
/>
</head>
<body className="font-sans antialiased">

The MobileSwipeFix PR accidentally removed the dark mode theme initialization script, suppressHydrationWarning, and body CSS classes from bundle-analyzer's root layout, breaking dark mode and font styling.

Fix on Vercel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Swipe back on mobile browser with getInitialProps flickers the previous page

1 participant