Skip to content

protocol+domain+port gets added to asPath after a HMR #4620

@Zn4rK

Description

@Zn4rK

Bug report

If I pass down ctx.ctx.asPath and print it in my <Component /> and then force a HMR, it'll add the protocol+domain+port to the beginning of asPath.

{
  "url": {
    "query": {},
    "pathname": "/",
    "asPath": "/"
  }
}

// After a bundle rebuild

{
  "url": {
    "query": {},
    "pathname": "/",
    "asPath": "http://localhost:3000/"
  }
}

To Reproduce

pages/_app.js:

import App, { Container } from 'next/app';
import React from 'react';

export default class MyApp extends App {
  static async getInitialProps ({ Component, router, ctx }) {
    const { query, pathname, asPath } = ctx;
    return { url: { query, pathname, asPath } };
  }

  render () {
    const {Component, url} = this.props;
    return (<Container><Component url={url} /></Container>);
  }
}

pages/index.js:

export default (props) => <pre>{JSON.stringify(props, null, 2)}</pre>;

Force a bundle rebuild by adding some text and save.

System information

  • Version of Next.js: 6.0.3

Other information

As discussed on Slack, it's related to this line.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions