Repository: storybook
Issue: [Bug]: Toolbar actions on Auto Generated Docs sometimes do not update the globals as expected when using nextjs framework
Labels: bug,nextjs,sev:S3

### Describe the bug

When accessing toolbar tool actions such as theme switcher, outline, etc in the autogenerated doc using nexts framework, the globals are not updated in the query params. This behavior does not happen all the time. Sometimes it updates the globals sometimes it does not. This problem ONLY exists in the autogenerated doc. 

This is the same issue as this https://github.com/storybookjs/storybook/issues/22636 . One thing to note is that this ONLY happens with the nextjs framework. 

Looking at the console we also see these errors using the nextjs framework:

```manager  received storyRenderPhaseChanged but was unable to determine the source of the event```


### To Reproduce

Run storybook using sandbox nexts 13 example [here](https://stackblitz.com/github/storybookjs/sandboxes/tree/next/nextjs/13-ts/after-storybook?file=.storybook%2Fmain.ts&preset=node). Open the console and go to the auto doc. Switch the background from light to dark the errors should popup in the console and sometimes the background does not switch.

Do the same thing but use the sandbox react vite example [here](https://stackblitz.com/github/storybookjs/sandboxes/tree/next/react-vite/default-ts/after-storybook?file=README.md&preset=node)

You see with react-bite or any other framework the error does not occur and the background switches consistently.

These examples are from storybook.new

### System

```bash
{
  "private": true,
  "scripts": {
    "dev": "next",
    "build": "next build",
    "start": "next start",
    "storybook": "storybook dev -p 6006",
    "build-storybook": "storybook build"
  },
  "dependencies": {
    "next": "^13.5.6",
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  },
  "devDependencies": {
    "@chromatic-com/storybook": "^1.2.20",
    "@storybook/addon-essentials": "^8.1.0-alpha.1",
    "@storybook/addon-interactions": "^8.1.0-alpha.1",
    "@storybook/addon-links": "^8.1.0-alpha.1",
    "@storybook/addon-onboarding": "^8.1.0-alpha.1",
    "@storybook/blocks": "^8.1.0-alpha.1",
    "@storybook/nextjs": "^8.1.0-alpha.1",
    "@storybook/react": "^8.1.0-alpha.1",
    "@storybook/test": "^8.1.0-alpha.1",
    "@types/node": "^17.0.43",
    "@types/react": "^18.0.12",
    "@types/react-dom": "^18.0.5",
    "storybook": "^8.1.0-alpha.1",
    "typescript": "^4.7.3"
  },
  "resolutions": {
    "@storybook/addon-a11y": "8.1.0-alpha.1",
    "@storybook/addon-actions": "8.1.0-alpha.1",
    "@storybook/addon-backgrounds": "8.1.0-alpha.1",
    "@storybook/addon-controls": "8.1.0-alpha.1",
    "@storybook/addon-docs": "8.1.0-alpha.1",
    "@storybook/addon-essentials": "8.1.0-alpha.1",
    "@storybook/addon-highlight": "8.1.0-alpha.1",
    "@storybook/addon-interactions": "8.1.0-alpha.1",
    "@storybook/addon-jest": "8.1.0-alpha.1",
    "@storybook/addon-links": "8.1.0-alpha.1",
    "@storybook/addon-mdx-gfm": "8.1.0-alpha.1",
    "@storybook/addon-measure": "8.1.0-alpha.1",
    "@storybook/addon-onboarding": "8.1.0-alpha.1",
    "@storybook/addon-outline": "8.1.0-alpha.1",
    "@storybook/addon-storysource": "8.1.0-alpha.1",
    "@storybook/addon-themes": "8.1.0-alpha.1",
    "@storybook/addon-toolbars": "8.1.0-alpha.1",
    "@storybook/addon-viewport": "8.1.0-alpha.1",
    "@storybook/angular": "8.1.0-alpha.1",
    "@storybook/blocks": "8.1.0-alpha.1",
    "@storybook/builder-manager": "8.1.0-alpha.1",
    "@storybook/builder-vite": "8.1.0-alpha.1",
    "@storybook/builder-webpack5": "8.1.0-alpha.1",
    "@storybook/channels": "8.1.0-alpha.1",
    "@storybook/cli": "8.1.0-alpha.1",
    "@storybook/client-logger": "8.1.0-alpha.1",
    "@storybook/codemod": "8.1.0-alpha.1",
    "@storybook/components": "8.1.0-alpha.1",
    "@storybook/core-common": "8.1.0-alpha.1",
    "@storybook/core-events": "8.1.0-alpha.1",
    "@storybook/core-server": "8.1.0-alpha.1",
    "@storybook/core-webpack": "8.1.0-alpha.1",
    "@storybook/csf-plugin": "8.1.0-alpha.1",
    "@storybook/csf-tools": "8.1.0-alpha.1",
    "@storybook/docs-tools": "8.1.0-alpha.1",
    "@storybook/ember": "8.1.0-alpha.1",
    "@storybook/html": "8.1.0-alpha.1",
    "@storybook/html-vite": "8.1.0-alpha.1",
    "@storybook/html-webpack5": "8.1.0-alpha.1",
    "@storybook/instrumenter": "8.1.0-alpha.1",
    "@storybook/manager": "8.1.0-alpha.1",
    "@storybook/manager-api": "8.1.0-alpha.1",
    "@storybook/nextjs": "8.1.0-alpha.1",
    "@storybook/node-logger": "8.1.0-alpha.1",
    "@storybook/preact": "8.1.0-alpha.1",
    "@storybook/preact-vite": "8.1.0-alpha.1",
    "@storybook/preact-webpack5": "8.1.0-alpha.1",
    "@storybook/preset-create-react-app": "8.1.0-alpha.1",
    "@storybook/preset-html-webpack": "8.1.0-alpha.1",
    "@storybook/preset-preact-webpack": "8.1.0-alpha.1",
    "@storybook/preset-react-webpack": "8.1.0-alpha.1",
    "@storybook/preset-server-webpack": "8.1.0-alpha.1",
    "@storybook/preset-svelte-webpack": "8.1.0-alpha.1",
    "@storybook/preset-vue3-webpack": "8.1.0-alpha.1",
    "@storybook/preview": "8.1.0-alpha.1",
    "@storybook/preview-api": "8.1.0-alpha.1",
    "@storybook/react": "8.1.0-alpha.1",
    "@storybook/react-dom-shim": "8.1.0-alpha.1",
    "@storybook/react-vite": "8.1.0-alpha.1",
    "@storybook/react-webpack5": "8.1.0-alpha.1",
    "@storybook/router": "8.1.0-alpha.1",
    "@storybook/server": "8.1.0-alpha.1",
    "@storybook/server-webpack5": "8.1.0-alpha.1",
    "@storybook/source-loader": "8.1.0-alpha.1",
    "@storybook/svelte": "8.1.0-alpha.1",
    "@storybook/svelte-vite": "8.1.0-alpha.1",
    "@storybook/svelte-webpack5": "8.1.0-alpha.1",
    "@storybook/sveltekit": "8.1.0-alpha.1",
    "@storybook/telemetry": "8.1.0-alpha.1",
    "@storybook/test": "8.1.0-alpha.1",
    "@storybook/theming": "8.1.0-alpha.1",
    "@storybook/types": "8.1.0-alpha.1",
    "@storybook/vue3": "8.1.0-alpha.1",
    "@storybook/vue3-vite": "8.1.0-alpha.1",
    "@storybook/vue3-webpack5": "8.1.0-alpha.1",
    "@storybook/web-components": "8.1.0-alpha.1",
    "@storybook/web-components-vite": "8.1.0-alpha.1",
    "@storybook/web-components-webpack5": "8.1.0-alpha.1",
    "sb": "8.1.0-alpha.1",
    "storybook": "8.1.0-alpha.1",
    "jackspeak": "2.1.1"
  }
}
```


### Additional context

_No response_