Skip to content

Commit

Permalink
Revert "Clean up eventsource initialization"
Browse files Browse the repository at this point in the history
This reverts commit 48b9e15.
  • Loading branch information
timneutkens committed Apr 13, 2021
1 parent 48b9e15 commit 35fee0d
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
6 changes: 4 additions & 2 deletions packages/next/client/dev/amp-dev.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* globals __webpack_hash__ */
import EventSourcePolyfill from './event-source-polyfill'
import { addMessageListener } from './error-overlay/eventsource'
import { getEventSourceWrapper } from './error-overlay/eventsource'
import { setupPing } from './on-demand-entries-utils'
import { displayContent } from './fouc'

Expand Down Expand Up @@ -68,7 +68,9 @@ async function tryApplyUpdates() {
}
}

addMessageListener((event) => {
getEventSourceWrapper({
path: `${assetPrefix}/_next/webpack-hmr`,
}).addMessageListener((event) => {
if (event.data === '\uD83D\uDC93') {
return
}
Expand Down
6 changes: 3 additions & 3 deletions packages/next/client/dev/dev-build-watcher.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { addMessageListener } from './error-overlay/eventsource'
import { getEventSourceWrapper } from './error-overlay/eventsource'

export default function initializeBuildWatcher(toggleCallback) {
const shadowHost = document.createElement('div')
Expand Down Expand Up @@ -39,8 +39,8 @@ export default function initializeBuildWatcher(toggleCallback) {
let timeoutId = null

// Handle events

addMessageListener((event) => {
const evtSource = getEventSourceWrapper({ path: '/_next/webpack-hmr' })
evtSource.addMessageListener((event) => {
// This is the heartbeat event
if (event.data === '\uD83D\uDC93') {
return
Expand Down
4 changes: 0 additions & 4 deletions packages/next/client/dev/error-overlay/eventsource.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ function EventSourceWrapper(options) {
}
}

export function addMessageListener(cb) {
eventCallbacks.push(cb)
}

export function getEventSourceWrapper(options) {
if (!options.ondemand) {
return {
Expand Down
6 changes: 3 additions & 3 deletions packages/next/client/dev/error-overlay/hot-dev-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

import * as DevOverlay from '@next/react-dev-overlay/lib/client'
import stripAnsi from 'next/dist/compiled/strip-ansi'
import { addMessageListener } from './eventsource'
import { getEventSourceWrapper } from './eventsource'
import formatWebpackMessages from './format-webpack-messages'

// This alternative WebpackDevServer combines the functionality of:
Expand All @@ -42,10 +42,10 @@ import formatWebpackMessages from './format-webpack-messages'

let hadRuntimeError = false
let customHmrEventHandler
export default function connect() {
export default function connect(options) {
DevOverlay.register()

addMessageListener((event) => {
getEventSourceWrapper(options).addMessageListener((event) => {
// This is the heartbeat event
if (event.data === '\uD83D\uDC93') {
return
Expand Down
6 changes: 2 additions & 4 deletions packages/next/client/dev/on-demand-entries-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ export function setupPing(assetPrefix, pathnameFn, retry) {
// close current EventSource connection
closePing()

evtSource = getEventSourceWrapper({
path: `${assetPrefix}/_next/webpack-hmr?page=${currentPage}`,
timeout: 5000,
})
const url = `${assetPrefix}/_next/webpack-hmr?page=${currentPage}`
evtSource = getEventSourceWrapper({ path: url, timeout: 5000, ondemand: 1 })

evtSource.addMessageListener((event) => {
if (event.data.indexOf('{') === -1) return
Expand Down
8 changes: 6 additions & 2 deletions packages/next/client/dev/webpack-hot-middleware-client.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import connect from './error-overlay/hot-dev-client'

export default () => {
const devClient = connect()
export default ({ assetPrefix }) => {
const options = {
path: `${assetPrefix}/_next/webpack-hmr`,
}

const devClient = connect(options)

devClient.subscribeToHmrEvent((obj) => {
if (obj.action === 'reloadPage') {
Expand Down
6 changes: 3 additions & 3 deletions packages/next/client/next-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import initOnDemandEntries from './dev/on-demand-entries-client'
import initWebpackHMR from './dev/webpack-hot-middleware-client'
import initializeBuildWatcher from './dev/dev-build-watcher'
import { displayContent } from './dev/fouc'
import { addMessageListener } from './dev/error-overlay/eventsource'
import { getEventSourceWrapper } from './dev/error-overlay/eventsource'
import * as querystring from '../next-server/lib/router/utils/querystring'

// Temporary workaround for the issue described here:
Expand All @@ -25,7 +25,7 @@ const {
} = window

const prefix = assetPrefix || ''
const webpackHMR = initWebpackHMR()
const webpackHMR = initWebpackHMR({ assetPrefix: prefix })

window.next = next
initNext({ webpackHMR })
Expand Down Expand Up @@ -72,7 +72,7 @@ initNext({ webpackHMR })
}
}
devPagesManifestListener.unfiltered = true
addMessageListener(devPagesManifestListener)
getEventSourceWrapper({}).addMessageListener(devPagesManifestListener)

if (process.env.__NEXT_BUILD_INDICATOR) {
initializeBuildWatcher((handler) => {
Expand Down

0 comments on commit 35fee0d

Please sign in to comment.