Skip to content

Commit

Permalink
fix(playground): tabs stackblitz example loads in Safari (#3287)
Browse files Browse the repository at this point in the history
  • Loading branch information
sean-perkins authored Dec 5, 2023
1 parent a006c22 commit 7ca32db
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
28 changes: 24 additions & 4 deletions src/components/global/Playground/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -546,10 +546,30 @@ export default function Playground({

if (hasUsageTargetOptions) {
editorOptions.files = Object.keys(codeSnippets[usageTarget])
.map((fileName) => ({
[fileName]: hostRef.current!.querySelector<HTMLElement>(`#${getCodeSnippetId(usageTarget, fileName)} code`)
.outerText,
}))
.map((fileName) => {
const codeBlock = hostRef.current!.querySelector<HTMLElement>(
`#${getCodeSnippetId(usageTarget, fileName)} code`
);
let code = codeBlock.outerText;

if (code.trim().length === 0) {
/**
* Safari has an issue where accessing the `outerText` on a non-visible
* DOM element results in a string with only whitespace. To work around this,
* we create a clone of the element, not attached to the DOM, and parse
* the outerText from that.
*
* Only in Safari does this persist whitespace & line breaks, so we
* explicitly check for when the code is empty to use this workaround.
*/
const el = document.createElement('div');
el.innerHTML = codeBlock.innerHTML;
code = el.outerText;
}
return {
[fileName]: code,
};
})
.reduce((acc, curr) => ({ ...acc, ...curr }), {});
editorOptions.dependencies = (code[usageTarget] as UsageTargetOptions).dependencies;
}
Expand Down
2 changes: 1 addition & 1 deletion static/usage/v6/tabs/router/angular/app_module_ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ExampleComponent } from './example.component';
import { AppRoutingModule } from './app-routing.module';

@NgModule({
imports: [BrowserModule, FormsModule, AppRoutingModule, IonicModule.forRoot()],
imports: [BrowserModule, FormsModule, AppRoutingModule, IonicModule.forRoot({})],
declarations: [AppComponent, ExampleComponent],
bootstrap: [AppComponent],
})
Expand Down
2 changes: 1 addition & 1 deletion static/usage/v7/tabs/router/angular/app_module_ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ExampleComponent } from './example.component';
import { AppRoutingModule } from './app-routing.module';

@NgModule({
imports: [BrowserModule, FormsModule, AppRoutingModule, IonicModule.forRoot()],
imports: [BrowserModule, FormsModule, AppRoutingModule, IonicModule.forRoot({})],
declarations: [AppComponent, ExampleComponent],
bootstrap: [AppComponent],
})
Expand Down

1 comment on commit 7ca32db

@vercel
Copy link

@vercel vercel bot commented on 7ca32db Dec 5, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

ionic-docs – ./

ionic-docs-gqykycf8t.vercel.app
ionic-docs-git-main-ionic1.vercel.app
ionic-docs-ionic1.vercel.app

Please sign in to comment.