Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix loading index.html in dev server when packager/optimizer changes bundle type #7527

Merged
merged 2 commits into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/core/core/src/public/Bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,12 @@ export class PackagedBundle extends NamedBundle implements IPackagedBundle {
);
}

get type(): string {
// The bundle type may be overridden in the packager.
// However, inline bundles will not have a bundleInfo here since they are not written to the filesystem.
return this.#bundleInfo ? this.#bundleInfo.type : this.#bundle.type;
}

get stats(): Stats {
return nullthrows(this.#bundleInfo).stats;
}
Expand Down
1 change: 1 addition & 0 deletions packages/core/core/src/requests/WriteBundleRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ async function run({input, options, api}: RunInput) {

let res = {
filePath,
type: info.type,
stats: {
size,
time: info.time ?? 0,
Expand Down
1 change: 1 addition & 0 deletions packages/core/core/src/requests/WriteBundlesRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ async function run({input, api, farm, options}: RunInput) {
let name = nullthrows(bundle.name).replace(bundle.hashReference, hash);
res.set(bundle.id, {
filePath: joinProjectPath(bundle.target.distDir, name),
type: bundle.type, // FIXME: this is wrong if the packager changes the type...
stats: {
time: 0,
size: 0,
Expand Down
1 change: 1 addition & 0 deletions packages/core/core/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ export type BundleGroupNode = {|

export type PackagedBundleInfo = {|
filePath: ProjectPath,
type: string,
stats: Stats,
|};

Expand Down
20 changes: 10 additions & 10 deletions packages/reporters/dev-server/src/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,16 @@ export default class Server {
sendIndex(req: Request, res: Response) {
if (this.bundleGraph) {
// If the main asset is an HTML file, serve it
let htmlBundleFilePaths = [];
this.bundleGraph.traverseBundles(bundle => {
if (bundle.type === 'html' && bundle.bundleBehavior !== 'inline') {
htmlBundleFilePaths.push(bundle.filePath);
}
});

htmlBundleFilePaths = htmlBundleFilePaths.map(p => {
return `/${relativePath(this.options.distDir, p, false)}`;
});
let htmlBundleFilePaths = this.bundleGraph
.getBundles()
Copy link
Member Author

Choose a reason for hiding this comment

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

getBundles excludes inline bundles by default

.filter(bundle => bundle.type === 'html')
.map(bundle => {
return `/${relativePath(
this.options.distDir,
bundle.filePath,
false,
)}`;
});

let indexFilePath = null;
if (htmlBundleFilePaths.length === 1) {
Expand Down