- Welcome to Next.js! + Welcome!!to Next.js!
diff --git a/examples/hello-next/styles/Home.module.css b/examples/hello-next/styles/Home.module.css
index 167d5f75bd..4a04160d03 100644
--- a/examples/hello-next/styles/Home.module.css
+++ b/examples/hello-next/styles/Home.module.css
@@ -1,6 +1,6 @@
@import url("./2.css");
.container {
- min-height: 100vh;
+ min-height: 99vh;
padding: 0 0.5rem;
display: flex;
flex-direction: column;
@@ -8,6 +8,8 @@
align-items: center;
height: 100vh;
}
+
+
.main {
padding: 5rem 0;
flex: 1;
diff --git a/package.json b/package.json
index 2052081df5..23453625a0 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"dependencies": {
"moment": "^2.29.1",
- "peechy": "^0.4.18",
+ "peechy": "^0.4.19",
"puppeteer": "^10.2.0",
"react": "^17.0.2",
"react-dom": "^17.0.2"
diff --git a/src/bundler.zig b/src/bundler.zig
index cc82ccf417..262a228889 100644
--- a/src/bundler.zig
+++ b/src/bundler.zig
@@ -2920,7 +2920,7 @@ pub const Transformer = struct {
var arena: std.heap.ArenaAllocator = undefined;
const use_arenas = opts.entry_points.len > 8;
- var ulimit: usize = Fs.FileSystem.RealFS.adjustUlimit();
+ var ulimit: usize = Fs.FileSystem.RealFS.adjustUlimit() catch unreachable;
var care_about_closing_files = !(FeatureFlags.store_file_descriptors and opts.entry_points.len * 2 < ulimit);
var transformer = Transformer{
diff --git a/src/css_scanner.zig b/src/css_scanner.zig
index 0adcd99174..41e43c22ee 100644
--- a/src/css_scanner.zig
+++ b/src/css_scanner.zig
@@ -1263,7 +1263,12 @@ pub fn NewBundler(
if (watcher_index == null) {
var file = try std.fs.openFileAbsolute(absolute_path, .{ .read = true });
+
try this.watcher.appendFile(file.handle, absolute_path, hash, .css, 0, null, true);
+ if (this.watcher.watchloop_handle == null) {
+ try this.watcher.start();
+ }
+
}
try this.import_queue.writeItem(hash);
diff --git a/src/fs.zig b/src/fs.zig
index 517dcdbd5e..2313dc17bb 100644
--- a/src/fs.zig
+++ b/src/fs.zig
@@ -541,16 +541,22 @@ pub const FileSystem = struct {
}
// Always try to max out how many files we can keep open
- pub fn adjustUlimit() usize {
- var limit = std.os.getrlimit(.NOFILE) catch return 32;
- if (limit.cur < limit.max) {
- var new_limit = std.mem.zeroes(std.os.rlimit);
- new_limit.cur = limit.max;
- new_limit.max = limit.max;
- std.os.setrlimit(.NOFILE, new_limit) catch return limit.cur;
- return new_limit.cur;
+ pub fn adjustUlimit() !usize {
+ const LIMITS = [_]std.os.rlimit_resource{std.os.rlimit_resource.STACK, std.os.rlimit_resource.NOFILE};
+ inline for (LIMITS) |limit_type, i| {
+ const limit = try std.os.getrlimit(limit_type);
+
+ if (limit.cur < limit.max) {
+ var new_limit = std.mem.zeroes(std.os.rlimit);
+ new_limit.cur = limit.max;
+ new_limit.max = limit.max;
+
+ try std.os.setrlimit(limit_type, new_limit);
+
+ }
+
+ if (i == LIMITS.len - 1) return limit.max;
}
- return limit.cur;
}
var _entries_option_map: *EntriesOption.Map = undefined;
@@ -559,7 +565,7 @@ pub const FileSystem = struct {
allocator: *std.mem.Allocator,
cwd: string,
) RealFS {
- const file_limit = adjustUlimit();
+ const file_limit = adjustUlimit() catch unreachable;
if (!_entries_option_map_loaded) {
_entries_option_map = EntriesOption.Map.init(allocator);
diff --git a/src/global.zig b/src/global.zig
index 236751a6bd..64d5f1a829 100644
--- a/src/global.zig
+++ b/src/global.zig
@@ -1,10 +1,15 @@
const std = @import("std");
pub usingnamespace @import("strings.zig");
+pub const Environment = @import("env.zig");
-pub const default_allocator: *std.mem.Allocator = if (isTest) std.heap.c_allocator else @import("./memory_allocator.zig").c_allocator;
+
+pub const default_allocator: *std.mem.Allocator = if (isTest or Environment.isLinux)
+ std.heap.c_allocator
+ else
+ @import("./memory_allocator.zig").c_allocator;
pub const C = @import("c.zig");
-pub const Environment = @import("env.zig");
+
pub usingnamespace Environment;
pub const FeatureFlags = @import("feature_flags.zig");
diff --git a/src/http.zig b/src/http.zig
index 0ddc02540b..72a4523272 100644
--- a/src/http.zig
+++ b/src/http.zig
@@ -50,6 +50,7 @@ threadlocal var req_headers_buf: [100]picohttp.Header = undefined;
threadlocal var res_headers_buf: [100]picohttp.Header = undefined;
const sync = @import("./sync.zig");
const JavaScript = @import("./javascript/jsc/javascript.zig");
+const JavaScriptCore = @import("./javascript/jsc/JavascriptCore.zig");
usingnamespace @import("./javascript/jsc/bindings/bindings.zig");
usingnamespace @import("./javascript/jsc/bindings/exports.zig");
const Router = @import("./router.zig");
@@ -1102,11 +1103,11 @@ pub const RequestContext = struct {
pub var channel: Channel = undefined;
var has_loaded_channel = false;
pub var javascript_disabled = false;
-
+ var js_thread: std.Thread = undefined;
pub fn spawnThread(handler: *HandlerThread) !void {
- var thread = try std.Thread.spawn(.{}, spawn, .{handler});
- thread.setName("WebSocket") catch {};
- thread.detach();
+ js_thread = try std.Thread.spawn(.{.stack_size = 64 * 1024 * 1024}, spawn, .{handler});
+ js_thread.setName("JavaScript SSR") catch {};
+ js_thread.detach();
}
pub fn spawn(handler: *HandlerThread) void {
@@ -1118,20 +1119,19 @@ pub const RequestContext = struct {
javascript_disabled = true;
}
var start_timer = std.time.Timer.start() catch unreachable;
+
var stdout = std.io.getStdOut();
- // var stdout = std.io.bufferedWriter(stdout_file.writer());
var stderr = std.io.getStdErr();
- // var stderr = std.io.bufferedWriter(stderr_file.writer());
var output_source = Output.Source.init(stdout, stderr);
- // defer stdout.flush() catch {};
- // defer stderr.flush() catch {};
+ defer Output.flush();
Output.Source.set(&output_source);
+
js_ast.Stmt.Data.Store.create(std.heap.c_allocator);
js_ast.Expr.Data.Store.create(std.heap.c_allocator);
- defer Output.flush();
+
var vm = JavaScript.VirtualMachine.init(
std.heap.c_allocator,
handler.args,
@@ -1947,6 +1947,8 @@ pub const RequestContext = struct {
// CSS handles this specially
if (loader != .css and client_entry_point_ == null) {
if (written.input_fd) |written_fd| {
+
+
try ctx.watcher.addFile(
written_fd,
result.file.input.text,
@@ -1958,8 +1960,9 @@ pub const RequestContext = struct {
);
if (ctx.watcher.watchloop_handle == null) {
- try ctx.watcher.start();
+ ctx.watcher.start() catch {};
}
+
}
} else {
if (written.written > 0) {
@@ -2008,6 +2011,7 @@ pub const RequestContext = struct {
if (file.autowatch) {
// we must never autowatch a file that will be closed
std.debug.assert(!file.close_handle_on_complete);
+
if (ctx.watcher.addFile(
file.fd,
result.file.input.text,
@@ -2438,16 +2442,6 @@ pub const Server = struct {
transform_options: Api.TransformOptions,
javascript_enabled: bool = false,
- pub fn adjustUlimit() !void {
- var limit = try std.os.getrlimit(.NOFILE);
- if (limit.cur < limit.max) {
- var new_limit = std.mem.zeroes(std.os.rlimit);
- new_limit.cur = limit.max;
- new_limit.max = limit.max;
- try std.os.setrlimit(.NOFILE, new_limit);
- }
- }
-
pub fn onTCPConnection(server: *Server, conn: tcp.Connection, comptime features: ConnectionFeatures) void {
conn.client.setNoDelay(true) catch {};
conn.client.setQuickACK(true) catch {};
@@ -2502,6 +2496,9 @@ pub const Server = struct {
defer ctx.watcher.flushEvictions();
defer Output.flush();
+ var rfs: *Fs.FileSystem.RealFS = &ctx.bundler.fs.fs;
+
+
// It's important that this function does not do any memory allocations
// If this blocks, it can cause cascading bad things to happen
for (events) |event| {
@@ -2526,7 +2523,6 @@ pub const Server = struct {
switch (kind) {
.file => {
if (event.op.delete or event.op.rename) {
- var rfs: *Fs.FileSystem.RealFS = &ctx.bundler.fs.fs;
ctx.watcher.removeAtIndex(
event.index,
0,
@@ -2559,12 +2555,12 @@ pub const Server = struct {
}
},
.directory => {
- var rfs: *Fs.FileSystem.RealFS = &ctx.bundler.fs.fs;
+
rfs.bustEntriesCache(file_path);
ctx.bundler.resolver.dir_cache.remove(file_path);
- if (event.op.delete or event.op.rename)
- ctx.watcher.removeAtIndex(event.index, hashes[event.index], parent_hashes, .directory);
+ // if (event.op.delete or event.op.rename)
+ // ctx.watcher.removeAtIndex(event.index, hashes[event.index], parent_hashes, .directory);
if (comptime is_emoji_enabled) {
Output.prettyln("