Skip to content

Commit

Permalink
Another config change to keep nextjs happy, cleanup wasm import hack
Browse files Browse the repository at this point in the history
  • Loading branch information
davidar committed Aug 4, 2024
1 parent a5d6545 commit 9e4ed57
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
7 changes: 1 addition & 6 deletions lib/atoms/wgputoyatoms.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';
import { atom } from 'jotai';
import { WgpuToyRenderer } from 'lib/wgputoy';
import { create_renderer, WgpuToyRenderer } from 'lib/wgputoy';
import { getDimensions } from '../../types/canvasdimensions';

// just to check if the object has already been freed (ptr=0)
Expand Down Expand Up @@ -29,14 +29,9 @@ type WgpuStatus = 'available' | 'unavailable' | 'unknown';
export const wgpuAvailabilityAtom = atom<WgpuStatus>('unknown');

export const wgputoyAtom = atom<Promise<WgpuToyRenderer | false>>(async get => {
// https://github.com/webpack/webpack/issues/11347
const wasm = await import('lib/wgputoy/wgputoy_bg.wasm');
const { __wbg_set_wasm, create_renderer } = await import('lib/wgputoy/wgputoy_bg.js');
if (!isSSR && get(canvasElAtom) !== false && get(canvasParentElAtom)) {
const parentEl = get(canvasParentElAtom);
const dim = getDimensions(parentEl.offsetWidth * window.devicePixelRatio);
console.log('Initialising WebGPU renderer');
__wbg_set_wasm(wasm);
return create_renderer(dim.x, dim.y, (get(canvasElAtom) as HTMLCanvasElement).id);
} else {
return false;
Expand Down
5 changes: 4 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ function getImageConfig() {
const nextConfig = {
reactStrictMode: true,
images: getImageConfig(),
experimental: {
esmExternals: 'loose'
},
async redirects() {
return [
{
Expand All @@ -41,7 +44,7 @@ const nextConfig = {
},
webpack(config, { isServer, dev }) {
config.experiments = {
syncWebAssembly: true,
asyncWebAssembly: true,
layers: true
};
if (isServer && !dev) {
Expand Down

0 comments on commit 9e4ed57

Please sign in to comment.