Skip to content

Commit

Permalink
Fix last issues with non-global ssr
Browse files Browse the repository at this point in the history
  • Loading branch information
SvanteRichter committed Apr 14, 2024
1 parent 81fbb31 commit 7b49999
Show file tree
Hide file tree
Showing 35 changed files with 840 additions and 195 deletions.
4 changes: 2 additions & 2 deletions examples/ssr/index.min.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "skruv",
"version": "0.7.4",
"version": "0.7.5",
"description": "No-dependency, no-build, small JS framework",
"keywords": [],
"bugs": {
Expand All @@ -24,15 +24,15 @@
},
"scripts": {
"build": "npm run build-ssr && npm run build-index && npm run build-jsx && npm run build-todo",
"build-index": "node ./utils/bundle.js skruv.js skruv.min.js",
"build-jsx": "(cd examples/jsx && node ../../utils/bundle.js index.tsx index.min.js)",
"build-ssr": "(cd examples/ssr && node ../../utils/bundle.js index.js index.min.js && node ../../utils/ssg.js 'https://skruv.io' index.min.js index.html)",
"build-todo": "(cd examples/todo && node ../../utils/bundle.js index.jsx index.min.js)",
"build-index": "node --experimental-vm-modules ./utils/bundle.js skruv.js skruv.min.js",
"build-jsx": "(cd examples/jsx && node --experimental-vm-modules ../../utils/bundle.js index.tsx index.min.js)",
"build-ssr": "(cd examples/ssr && node --experimental-vm-modules ../../utils/bundle.js index.js index.min.js && node --experimental-vm-modules ../../utils/ssg.js 'https://skruv.io' index.min.js index.html)",
"build-todo": "(cd examples/todo && node --experimental-vm-modules ../../utils/bundle.js index.jsx index.min.js)",
"cleanup": "find . -maxdepth 1 -iname '*.d.ts' -delete && find utils examples tests -iname '*.d.ts' -delete && find . -maxdepth 1 -iname '*.map' -delete && find utils examples tests -iname '*.map' -delete && find . -maxdepth 1 -iname '*.min.js' -delete && find utils examples tests -iname '*.min.js' -delete",
"deno-ssr": "npm run build-ssr && (cd ./examples/ssr && deno run --allow-net --allow-read ./deno-ssr.js)",
"lint": "eslint . --ext js,jsx,json",
"pre-release": "npm run cleanup && npm run build && npm run test && npm run lint -- --fix && npm run typecheck && gzip -9kf skruv.min.js && brotli -Zkf skruv.min.js && du --apparent-size --bytes skruv.min.j* skruv.js && rm -f skruv.min.js.{gz,br}",
"ssr": "npm run build-ssr && (cd ./examples/ssr && node ../../utils/ssr.js index.min.js)",
"ssr": "npm run build-ssr && (cd ./examples/ssr && node --experimental-vm-modules ../../utils/ssr.js index.min.js)",
"test": "node --test --experimental-test-coverage --test-reporter=spec",
"typecheck": "tsc"
},
Expand Down
4 changes: 3 additions & 1 deletion skruv.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const render = (
if (currentNode) { parentNode.removeChild(currentNode) }
return
}
// @ts-ignore
if (!globalThis?.isSkruvSSR && current?.t?.toLowerCase() === 'skruvtext' && current?.c?.[0]) {
current.r = () => {
// @ts-expect-error
Expand Down Expand Up @@ -87,7 +88,8 @@ export const render = (
if (current.t === 'foreignObject') { ns = htmlNS }
/** @type {import("./utilityTypes").Vnode[]} */
// @ts-expect-error
let children = current.c.flat(Infinity)
let children = current.c.flat(Infinity)/** @type {string | URL} */
// @ts-expect-error
if (!globalThis?.isSkruvSSR) { children = children.filter(c => !c?.t?.startsWith('skruv')) }
/** @type {import("./utilityTypes").attributes} */
// @ts-expect-error
Expand Down
4 changes: 2 additions & 2 deletions skruv.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/atom.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../utils/minidom.js'
import './globals.js'

import assert from 'node:assert'
import test from 'node:test'
Expand Down
2 changes: 1 addition & 1 deletion tests/css.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../utils/minidom.js'
import './globals.js'

import assert from 'node:assert'
import test from 'node:test'
Expand Down
2 changes: 2 additions & 0 deletions tests/errors.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import './globals.js'

import assert from 'node:assert'
import test from 'node:test'

Expand Down
2 changes: 1 addition & 1 deletion tests/escaping.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../utils/minidom.js'
import './globals.js'

import assert from 'node:assert'
import fs from 'node:fs/promises'
Expand Down
2 changes: 2 additions & 0 deletions tests/generator.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import './globals.js'

import assert from 'node:assert'
import test from 'node:test'

Expand Down
2 changes: 1 addition & 1 deletion tests/generator_attribute.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../utils/minidom.js'
import './globals.js'

import assert from 'node:assert'
import test from 'node:test'
Expand Down
1 change: 1 addition & 0 deletions tests/globals.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
5 changes: 5 additions & 0 deletions tests/globals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { createContext } from '../utils/minidom.js'

const context = createContext()
// @ts-expect-error
for (const key in context) { globalThis[key] = context[key] }
2 changes: 1 addition & 1 deletion tests/jsx.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global Location */
import '../utils/minidom.js'
import './globals.js'

import assert from 'node:assert'
import test from 'node:test'
Expand Down
2 changes: 2 additions & 0 deletions tests/key.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import './globals.js'

import assert from 'node:assert'
import test from 'node:test'

Expand Down
2 changes: 1 addition & 1 deletion tests/loader.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../utils/minidom.js'
import './globals.js'

import assert from 'node:assert'
import test from 'node:test'
Expand Down
2 changes: 1 addition & 1 deletion tests/mathml-in-html.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global MathMLElement HTMLElement */
import '../utils/minidom.js'
import './globals.js'

import assert from 'node:assert'
import test from 'node:test'
Expand Down
2 changes: 1 addition & 1 deletion tests/mathml.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global MathMLElement */
import '../utils/minidom.js'
import './globals.js'

import assert from 'node:assert'
import test from 'node:test'
Expand Down
2 changes: 1 addition & 1 deletion tests/minidom.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global Location */
import '../utils/minidom.js'
import './globals.js'

import assert from 'node:assert'
import test from 'node:test'
Expand Down
2 changes: 1 addition & 1 deletion tests/render.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../utils/minidom.js'
import './globals.js'

import assert from 'node:assert'
import test from 'node:test'
Expand Down
2 changes: 1 addition & 1 deletion tests/render_deep.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../utils/minidom.js'
import './globals.js'

import assert from 'node:assert'
import test from 'node:test'
Expand Down
2 changes: 1 addition & 1 deletion tests/render_wide.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../utils/minidom.js'
import './globals.js'

import assert from 'node:assert'
import test from 'node:test'
Expand Down
2 changes: 1 addition & 1 deletion tests/root-text.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../utils/minidom.js'
import './globals.js'

import assert from 'node:assert'
import test from 'node:test'
Expand Down
2 changes: 1 addition & 1 deletion tests/state_array.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../utils/minidom.js'
import './globals.js'

import assert from 'node:assert'
import test from 'node:test'
Expand Down
2 changes: 1 addition & 1 deletion tests/state_object.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../utils/minidom.js'
import './globals.js'

import assert from 'node:assert'
import test from 'node:test'
Expand Down
2 changes: 1 addition & 1 deletion tests/svg-in-html.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global SVGElement HTMLElement */
import '../utils/minidom.js'
import './globals.js'

import assert from 'node:assert'
import test from 'node:test'
Expand Down
2 changes: 1 addition & 1 deletion tests/svg.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global SVGElement HTMLElement */
import '../utils/minidom.js'
import './globals.js'

import assert from 'node:assert'
import test from 'node:test'
Expand Down
2 changes: 1 addition & 1 deletion tests/switch_type.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../utils/minidom.js'
import './globals.js'

import assert from 'node:assert'
import test from 'node:test'
Expand Down
3 changes: 3 additions & 0 deletions utils/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,13 @@ export const css = (strings, ...keys) => {
return retval
}
let sheet
// @ts-ignore
if (!globalThis?.CSSOM && !globalThis.document?.implementation) {
throw new Error('No css parser available. Either add CSSOM to globalThis or run in browser.')
}
// @ts-ignore
if (globalThis?.CSSOM) {
// @ts-ignore
sheet = CSSOM.parse(stylesheet)
} else {
// In FF/Chrome we could create the sheet with new CSSStyleSheet(), but that does not work in safari lower than 16.4 (Released 2023-03-27)
Expand Down
Loading

0 comments on commit 7b49999

Please sign in to comment.