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(ssr): include <style /> for scope components when fullDocument: false #6155

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
"sys/",
"testing/"
],
"browser": {
"node:fs": false,
"node:path": false
},
"exports": {
".": {
"import": "./internal/stencil-core/index.js",
Expand Down
21 changes: 21 additions & 0 deletions src/mock-doc/serialize-node.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { BUILD } from '@platform';

Check failure on line 1 in src/mock-doc/serialize-node.ts

View workflow job for this annotation

GitHub Actions / Lint and Format / Check

Run autofix to sort these imports!
import {
CONTENT_REF_ID,
HYDRATE_ID,
Expand Down Expand Up @@ -63,13 +64,33 @@
};

let renderedNode = '';

const children =
!opts.fullDocument && (elm as MockDocument).body
? Array.from((elm as MockDocument).body.childNodes)
: opts.outerHtml
? [elm]
: Array.from(getChildNodes(elm));

// If we are not serializing the full document and we're not exclusively using declarative shadow dom
// we need to make sure we also include the style element for any components that are being hydrated
if (
!opts.fullDocument &&
(BUILD.scoped || (opts.serializeShadowRoot !== 'declarative-shadow-dom' && opts.serializeShadowRoot !== true))
) {
for (let i = 0, ii = children.length; i < ii; i++) {
const child = children[i] as HTMLElement;
if (child.tagName) {
const styleTag = (elm as Element).querySelector(
`style[sty-id="sc-${(child as Element).tagName.toLowerCase()}"]`
);
if (styleTag) {
child.prepend(styleTag);
}
}
}
}

for (let i = 0, ii = children.length; i < ii; i++) {
const child = children[i];
const chunks = Array.from(streamToHtml(child, opts, output));
Expand Down
2 changes: 1 addition & 1 deletion src/utils/output-target.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { flatOne, normalizePath, sortBy } from '@utils';

Check failure on line 1 in src/utils/output-target.ts

View workflow job for this annotation

GitHub Actions / Lint and Format / Check

Run autofix to sort these imports!
import { join } from '@utils';
import { basename, dirname, relative } from 'path';
import { basename, dirname, relative } from 'node:path';

import type * as d from '../declarations';
import {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/path.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from 'path';
import path from 'node:path';

/**
* Convert Windows backslash paths to slash paths: foo\\bar ➔ foo/bar
Expand Down
Loading